Jump to content

Attila Kovacs

Members
  • Content Count

    1977
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by Attila Kovacs

  1. 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
  2. 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.
  3. 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.
  4. 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?
  5. 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.
  6. There are the Explicit* properties in the dfm which are storing the design time positions and sizes. If you are not striping them.
  7. 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;
  8. Attila Kovacs

    GExperts 1.3.18 experimental twm 2021-02-21 released

    You let the genie out of the bottle 😜 🀐
  9. 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.
  10. Attila Kovacs

    SQLite, adding a function

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

    SQLite, adding a function

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

    remove ExplicitXxxx properties

    forget it, must be something else.
  13. 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.
  14. 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". πŸ™‚
  15. 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.
  16. Attila Kovacs

    Generic set comparer

    solved, user error.
  17. Attila Kovacs

    Generic set comparer

    LOL <o>, well, now it's revealed! πŸ˜‰
  18. Attila Kovacs

    Generic set comparer

    @Leif Uneus Wow, thanks a lot, and also to LU RD if he ever reads this.
  19. Attila Kovacs

    Generic set comparer

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

    DB Blob being converted to Unicode and should not be

    depending on the DAC you are using you could try "Data Type Mapping"
  21. Attila Kovacs

    DB Blob being converted to Unicode and should not be

    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?
  22. Attila Kovacs

    DB Blob being converted to Unicode and should not be

    What kind of DB and Field type and DAC? Can you read the data fine with the D2007 app?
  23. Attila Kovacs

    DB Blob being converted to Unicode and should not be

    does the blob editor showing it in raw hex? do you read the blob as blobfield and stream or as string?
  24. Attila Kovacs

    Quickly zero all local variables?

    We're approaching levels unseen.
Γ—