-
Content Count
1977 -
Joined
-
Last visited
-
Days Won
26
Everything posted by Attila Kovacs
-
Read and reapply design time properties to specific controls - runtime
Attila Kovacs replied to aehimself's topic in VCL
Re-read with TReader -> yes, see my previous comment Re-apply with TReader -> no, but you can reapply it by updating the corresponding properties by yourself -
Native Svg parsing and painting in Windows
Attila Kovacs replied to pyscripter's topic in RTL and Delphi Object Pascal
I did not feel the need to get PowerToys' preview criticized. It has nothing to do with the language it's written in. It's all about preferences. No. As I'm preparing the images for production and then it gets into a separate directory, and depending on the selected theme, dark or light, the colors in the SVG's are adjusted for all icons automatically on theme change. We sure not doing the same job. -
Native Svg parsing and painting in Windows
Attila Kovacs replied to pyscripter's topic in RTL and Delphi Object Pascal
<o> There is no thumbnail if you are in list or detail mode and it makes no sense to have the preview pane turned on if you are in icon-list mode and you can see the thumbnails. I understand that you like to turn the windows explorer into an full armed SVG workshop, I'm just saying that sometimes less is more. And it's definitely not slower. At least not on the usual SVG context. I admit that the white background could be a showstopper on dark themes, but this is a subject for a separate thread. Dark theme with bright text is very very bad for the eyes. -
Native Svg parsing and painting in Windows
Attila Kovacs replied to pyscripter's topic in RTL and Delphi Object Pascal
Really? I find it faster and more pleasant. Also it does not create a flashing parented form/frame + editor etc. on the preview pane every time a file is selected. Minimalist? What should be on an svg preview pane except the image itself? -
Read and reapply design time properties to specific controls - runtime
Attila Kovacs replied to aehimself's topic in VCL
I think this is what you need, you just have to adjust it a bit. // search in dfm resources by Attila Kovacs unit DFMSearch; interface uses System.Classes, System.Generics.Collections; type TDFMSearch = class private FFormClasses: TList<string>; FResourceNames: TList<string>; FSearchDictionary: TDictionary<string, string>; function GetFormClasses(AClass: TClass): TList<string>; procedure BuildStrings(AResources: TList<string>); procedure EnumClasses(AClass: TClass); public function Find(const ASearchString: string): TList<string>; constructor Create(AClass: TClass); overload; constructor Create(AClassNames: TList<string>); overload; destructor Destroy; override; end; implementation uses Winapi.Windows, System.Rtti, System.SysUtils, System.StrUtils; function EnumResNames(Module: HMODULE; ResType, ResName: PChar; Obj: Pointer): integer; stdcall; var ds: TDFMSearch; begin ds := TDFMSearch(Obj); if ds.FFormClasses.IndexOf(string(ResName)) > -1 then ds.FResourceNames.Add(string(ResName)); Result := 1; end; function TDFMSearch.GetFormClasses(AClass: TClass): TList<string>; var cl: TClass; ctx: TRttiContext; types: TArray<TRttiType>; typ: TRttiType; begin Result := TList<string>.Create; ctx := TRttiContext.Create; types := ctx.GetTypes; for typ in types do begin if typ.TypeKind = tkClass then begin cl := typ.AsInstance.MetaclassType; if (cl <> AClass) and cl.InheritsFrom(AClass) then Result.Add(UpperCase(cl.ClassName)); end; end; end; procedure TDFMSearch.BuildStrings(AResources: TList<string>); var i: integer; Flags: TFilerFlags; R: TReader; RS: Tresourcestream; vt: TValueType; Position: integer; text, PropName, CompClass, CompName, StrValue, ResStr: string; procedure ReadProperty; begin PropName := R.ReadStr; if ContainsText(PropName, 'caption') then begin vt := R.NextValue; case vt of vaWString, vaUTF8String: StrValue := R.ReadString; vaString, vaLString: StrValue := R.ReadString; else R.SkipValue; end; text := text + ' ' + StrValue; end else R.SkipValue; end; procedure ReadData; forward; procedure ReadComponent; begin R.ReadPrefix(Flags, Position); CompClass := R.ReadStr; CompName := R.ReadStr; ReadData; end; procedure ReadData; begin while not R.EndOfList do ReadProperty; R.ReadListEnd; while not R.EndOfList do ReadComponent; R.ReadListEnd; end; begin for i := 0 to AResources.Count - 1 do begin ResStr := UpperCase(AResources[i]); RS := Tresourcestream.Create(HInstance, ResStr, RT_RCDATA); try R := TReader.Create(RS, 4096); try text := ''; R.ReadSignature; ReadComponent; FSearchDictionary.AddOrSetValue(ResStr, text); finally R.Free; end; finally RS.Free; end; end; end; constructor TDFMSearch.Create(AClass: TClass); begin FSearchDictionary := TDictionary<string, string>.Create; EnumClasses(AClass); end; constructor TDFMSearch.Create(AClassNames: TList<string>); begin FSearchDictionary := TDictionary<string, string>.Create; BuildStrings(AClassNames); end; destructor TDFMSearch.Destroy; begin FSearchDictionary.Free; inherited; end; procedure TDFMSearch.EnumClasses(AClass: TClass); begin if not Assigned(FSearchDictionary) then begin FFormClasses := GetFormClasses(AClass); try FResourceNames := TList<string>.Create; try EnumResourceNames(HInstance, RT_RCDATA, @EnumResNames, NativeInt(Self)); BuildStrings(FResourceNames); finally FResourceNames.Free; end; finally FFormClasses.Free; end; end; end; function TDFMSearch.Find(const ASearchString: string): TList<string>; var i, j, slen: integer; sl: TArray<string>; pa: TPair<string, string>; begin Result := TList<string>.Create; sl := ASearchString.Split([' ']); slen := Length(sl); for pa in FSearchDictionary do begin j := 0; for i := 0 to High(sl) do begin if ContainsText(pa.Value, sl[i]) then inc(j); end; if j = slen then Result.Add(pa.Key); end; end; end. -
Read and reapply design time properties to specific controls - runtime
Attila Kovacs replied to aehimself's topic in VCL
There are the Explicit* properties in the dfm which are storing the design time positions and sizes. If you are not striping them. -
Micro optimization: Split strings
Attila Kovacs replied to Mike Torrettinni's topic in Algorithms, Data Structures and Class Design
My version is rather fun as some kind of pico-optimization. An on the fly enumerator! And also fast and low memory footprint. (And unidirectional π TSplitEnumerator = class; TSplit = record private PValue: pointer; PDelimiter: pointer; public function GetEnumerator: TSplitEnumerator; class function Create(const AValue: string; const ADelimiter: string): TSplit; static; end; TSplitEnumerator = class private FValue: string; FDelimiter: string; FHasNext: boolean; FIndex: integer; FNIndex: integer; FLen: integer; FDelLen: integer; public constructor Create(const ASplit: TSplit); function MoveNext: boolean; {$IFNDEF DEBUG} inline; {$ENDIF} function GetCurrent: string; {$IFNDEF DEBUG} inline; {$ENDIF} property Current: string read GetCurrent; end; { TSplit } class function TSplit.Create(const AValue: string; const ADelimiter: string): TSplit; begin Result.PValue := pointer(AValue); Result.PDelimiter := pointer(ADelimiter); end; function TSplit.GetEnumerator: TSplitEnumerator; begin Result := TSplitEnumerator.Create(Self); end; { TSplitEnumerator } constructor TSplitEnumerator.Create(const ASplit: TSplit); begin FIndex := 1; pointer(FValue) := ASplit.PValue; pointer(FDelimiter) := ASplit.PDelimiter; FLen := Length(FValue); FDelLen := Length(FDelimiter); FNIndex := Pos(FDelimiter, FValue, FIndex); if (FNIndex = 0) then FNIndex := FIndex + FLen; FHasNext := (FLen > 0) and (FNIndex > 0); end; function TSplitEnumerator.GetCurrent: string; begin Result := Copy(FValue, FIndex, FNIndex - FIndex); if FNIndex + FDelLen < FLen then begin FIndex := FNIndex + FDelLen; FNIndex := Pos(FDelimiter, FValue, FIndex); if FNIndex = 0 then FNIndex := FLen + FDelLen; end else FHasNext := False; end; function TSplitEnumerator.MoveNext: boolean; begin Result := FHasNext; end; var s: string; begin for s in TSplit.Create(cShortStr, cDelimiter) do WriteLn(s); end; -
GExperts 1.3.18 experimental twm 2021-02-21 released
Attila Kovacs replied to dummzeuch's topic in GExperts
You let the genie out of the bottle π π€ -
GExperts 1.3.18 experimental twm 2021-02-21 released
Attila Kovacs replied to dummzeuch's topic in GExperts
@FredS Ahm, I know this! "In welchen saisonalen ZeitrΓ€umen sind Coronaviren in Mitteleuropa normalerweise aktiv?" except summer holiday and xmas, 05:00-19:59. -
@Dany Marmur Because the server works faster if you are shouting π
-
@Dany Marmur By the way, do you know why SQL Queries are written in capital letters? π
-
forget it, must be something else.
-
It's not a problem if you use your own TForm descendant as base. Ofc. it's also a bit work to change everything now. I did it back to the days to handle some HDPI bugs.
-
Firedac FDBatchMove.Execute error when last line in double-quote CSV file does not contain linefeed
Attila Kovacs replied to egnew's topic in Databases
This raises a question for me. π€- 6 replies
-
- firedac
- fdbatchmove
-
(and 1 more)
Tagged with:
-
I'm sure there is a mass property modifier in one of the popular experts. Worst case, there is always "sed". π
-
Is there a mature library for generic (multi)set operations? (Edit: Reading my topic, i meant mathematical sets, maybe I could name it List instead of set, the result what counts) I'd imagine that working like this: unit xyz.sets; interface uses System.Generics.Defaults; type TSets<T> = class public type TSet = class private FValues: TArray<T>; public procedure Add(AValue: T); end; private var FSets: TArray<TSet>; FComparer: IEqualityComparer<T>; public constructor Create; function AddSet: TSet; function GetIntersection(ASets: array of TSet): TArray<T>; property Comparer: IEqualityComparer<T> read FComparer write FComparer; end; implementation uses System.SysUtils; { TSets<T> } function TSets<T>.AddSet: TSet; var l: integer; begin Result := TSet.Create; l := Length(FSets); SetLength(FSets, l + 1); FSets[l] := Result; end; { TSets<T>.TSet } procedure TSets<T>.TSet.Add(AValue: T); var l: integer; begin l := Length(FValues); SetLength(FValues, l + 1); FValues[l] := AValue; end; constructor TSets<T>.Create; begin FComparer := TEqualityComparer<T>.Default; end; // O(n^x) function TSets<T>.GetIntersection(ASets: array of TSet): TArray<T>; var i, j, k, l: integer; begin if FComparer = nil then raise Exception.Create('No comparer defined.'); if Length(ASets) > 1 then begin for i := 0 to High(ASets[0].FValues) do for j := 1 to High(ASets) do for k := 0 to High(ASets[j].FValues) do if FComparer.Equals(ASets[0].FValues[i], ASets[j].FValues[k]) then begin l := Length(Result); SetLength(Result, l + 1); Result[l] := ASets[0].FValues[i]; end; end else Result := ASets[0].FValues; end; end. ------ β ------ β ------ β ------ β ------ β ------ β ------ β ------ β ------ program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, xyz.sets in 'xyz.sets.pas'; var rp: procedure; i: integer; sets: TSets<string>; set1, set2: TSets<string>.TSet; res: TArray<string>; procedure x; begin ExitProcessProc := rp; ReadLn; end; begin ReportMemoryLeaksOnShutdown := True; rp := ExitProcessProc; ExitProcessProc := x; sets := TSets<string>.Create; set1 := sets.AddSet; set2 := sets.AddSet; try set1.Add('hello'); set1.Add('leo'); set2.Add('hello'); set2.Add('bello'); res := sets.GetIntersection([set1, set2]); for i := 0 to High(res) do WriteLn(res[i]); finally set1.Free; set2.Free; sets.Free; end; end.
-
Generic set comparer
Attila Kovacs replied to Attila Kovacs's topic in Algorithms, Data Structures and Class Design
solved, user error. -
Generic set comparer
Attila Kovacs replied to Attila Kovacs's topic in Algorithms, Data Structures and Class Design
LOL <o>, well, now it's revealed! π -
Generic set comparer
Attila Kovacs replied to Attila Kovacs's topic in Algorithms, Data Structures and Class Design
@Leif Uneus Wow, thanks a lot, and also to LU RD if he ever reads this. -
Generic set comparer
Attila Kovacs replied to Attila Kovacs's topic in Algorithms, Data Structures and Class Design
Ahm, i was afraid that using the word "set" would be misleading, and I was right, sorry, but lists are a bit different from multisets again, so I don't know, I need to compare two or more "set of anything" and I'm tired writing it always manually. -
DB Blob being converted to Unicode and should not be
Attila Kovacs replied to Bill Meyer's topic in Databases
depending on the DAC you are using you could try "Data Type Mapping" -
DB Blob being converted to Unicode and should not be
Attila Kovacs replied to Bill Meyer's topic in Databases
I'm not an IB expert but IB BLOB has a default subtype = text. Maybe it was the whole time stored with that subtype but it was fine with ansistrings? -
DB Blob being converted to Unicode and should not be
Attila Kovacs replied to Bill Meyer's topic in Databases
What kind of DB and Field type and DAC? Can you read the data fine with the D2007 app? -
DB Blob being converted to Unicode and should not be
Attila Kovacs replied to Bill Meyer's topic in Databases
does the blob editor showing it in raw hex? do you read the blob as blobfield and stream or as string? -
Quickly zero all local variables?
Attila Kovacs replied to A.M. Hoornweg's topic in RTL and Delphi Object Pascal
We're approaching levels unseen.