Jump to content

Attila Kovacs

Members
  • Content Count

    1936
  • Joined

  • Last visited

  • Days Won

    25

Everything posted by Attila Kovacs

  1. Attila Kovacs

    TTreeNode leak when VCL styles are active

    reproduced with Berlin U2
  2. Attila Kovacs

    Micro optimization: Split strings

    @Fr0sT.Brutal cool, this also helped me to spot some bugs in my enum version. do you have a unit test for it?
  3. Attila Kovacs

    TTreeNode leak when VCL styles are active

    an MCVE would be nice as we could figure out which version are affected and also debug it instead of guessing
  4. Attila Kovacs

    TTreeNode leak when VCL styles are active

    Do we know wich Delphi versions are affected?
  5. Attila Kovacs

    XLS 2 XLSX

    Sorry, it's "--outdir", you can check the parameters with "--help". Yes, *nix style. That's why the "*.xls" also doesn't work. (<o> free software) You can also create a batch file with "for in" and call that. https://ask.libreoffice.org/en/question/253696/using-wildcards-for-windows-command-line-batch-convert/
  6. Attila Kovacs

    Max string literal length = 255

    can we ban this clown @Lars Fosdal?
  7. He also mentions that he is successfully hides/resizes/rearranges those components. That said, I can't see any problem to reset them. Also, I trust him fully that he knows what he is doing.
  8. @balabuev TWinControl.DisableAlign may help there
  9. If there are some non-standard written controls which has to be restored, yes, you are right, it would need it's reader. On standard controls you can skip the data you don't need or you don't know. We can't see this from here. Nor the actual software to be able to decide which would be less effort, storing local the initial values or reading the dfm. I wanted to show him how to read the resources by its classtypes and read some properties, which he asked.
  10. 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
  11. Attila Kovacs

    Native Svg parsing and painting in Windows

    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.
  12. Attila Kovacs

    Native Svg parsing and painting in Windows

    <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.
  13. Attila Kovacs

    Native Svg parsing and painting in Windows

    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?
  14. 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.
  15. There are the Explicit* properties in the dfm which are storing the design time positions and sizes. If you are not striping them.
  16. Attila Kovacs

    Micro optimization: Split strings

    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;
  17. Attila Kovacs

    GExperts 1.3.18 experimental twm 2021-02-21 released

    You let the genie out of the bottle 😜 🀐
  18. Attila Kovacs

    GExperts 1.3.18 experimental twm 2021-02-21 released

    @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.
  19. Attila Kovacs

    SQLite, adding a function

    @Dany Marmur Because the server works faster if you are shouting πŸ˜›
  20. Attila Kovacs

    SQLite, adding a function

    @Dany Marmur By the way, do you know why SQL Queries are written in capital letters? πŸ˜‰
  21. Attila Kovacs

    remove ExplicitXxxx properties

    forget it, must be something else.
  22. Attila Kovacs

    Keep D2006 vs Sydney aligned

    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.
  23. Attila Kovacs

    Keep D2006 vs Sydney aligned

    I'm sure there is a mass property modifier in one of the popular experts. Worst case, there is always "sed". πŸ™‚
  24. 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.
Γ—