Picture.LoadFromFile('c:\bla\bla\image.png'); Picture.Graphic.ClassName; In principle, in practice it is enough for testing or debugging. But I was wondering how to get all the classes registered in RegisterFileFormat. function GetStackTraceAsText(AReturnAddresses: PNativeUInt): string; var LErrorMessage: array[0..32767] of AnsiChar; LMsgPtr: PAnsiChar; begin LMsgPtr := LogStackTrace(AReturnAddresses, StackTraceDepth, @LErrorMessage[0]); inc(LMsgPtr); LMsgPtr^ := #0; Result := LErrorMessage; end; Further, the demo code with comments, I hope understandable without additional descriptions. The essence of the solution is described in GetGraphClasses. program LogRegisterFileFormat; {$APPTYPE CONSOLE} uses FastMM4, { FastMM4Options.inc FullDebugModeCallBacks FullDebugMode} SysUtils, Classes, Graphics, Jpeg, pngimage; var LastClassName: string; function GetClassCreateLine(AStack: string): string; { } var P: Integer; L: Integer; R: Integer; begin P := Pos('.Create]', AStack); if P > 0 then begin L := P; while (L > 1) and (AStack[L] > #32) do dec(L); inc(L); R := P; while (R < Length(AStack)) and (AStack[R] > #32) do inc(R); Result := Copy(AStack, L, R - L); end else Result := AStack; end; procedure DoCustomMemFree(APHeaderFreedBlock: PFullDebugBlockHeader; AResult: Integer); { } var LClass: TClass; begin { } LClass := DetectClassInstance(@APHeaderFreedBlock.PreviouslyUsedByClass); if LClass <> nil then begin { TGraphic LastClassName } if LClass.InheritsFrom(TGraphic) then begin LastClassName := LClass.ClassName; { , } if APHeaderFreedBlock.AllocationStackTrace[0] <> 0 then LastClassName := LastClassName + ' ' + GetClassCreateLine(GetStackTraceAsText(@APHeaderFreedBlock.AllocationStackTrace)); end; end; end; function Fetch(var Value: string; const Delimiter: string): string; { Value . Synapse, } var P: Integer; begin P := Pos(Delimiter, Value); if P < 1 then begin Result := Value; Value := ''; end else begin Result := Copy(Value, 1, P - 1); Delete(Value, 1, P + Length(Delimiter)); end; Result := Trim(Result); Value := Trim(Value); end; procedure GetGraphClasses(const AStrings: TStrings); var Filters: string; FileMask: string; FileExt: string; Pic: TPicture; begin { '*.png;*.jpg'} Filters := GraphicFileMask(TGraphicClass(TObject)); { } FileMask := Fetch(Filters, ';'); while Length(FileMask) > 0 do begin Pic := TPicture.Create; FileExt := ExtractFileExt(FileMask); try try LastClassName := ''; { } FastMM4.OnDebugFreeMemFinish := DoCustomMemFree; { . LoadFromFile, . DoCustomMemFree } Pic.LoadFromFile(FileExt); { - , , , } if Pic.Graphic <> nil then AStrings.Add(FileMask + ' = ' + Pic.Graphic.ClassName); except { . LastClassName .} AStrings.Add(FileMask + ' = ' + LastClassName); LastClassName := ''; end; finally FreeAndNil(Pic); FastMM4.OnDebugFreeMemFinish := nil; end; { Filters} FileMask := Fetch(Filters, ';'); end; end; var Log: TStringList; begin Log := TStringList.Create; GetGraphClasses(Log); Log.SaveToFile(ParamStr(0) + '.log'); Log.Free; end. Source: https://habr.com/ru/post/192944/
All Articles