in Delphi language, I need Class Helpers so I can add to every TComponent descendant a…
- User
in Delphi language, I need Class Helpers so I can add to every TComponent descendant a property of type TQryRecInfo named ORMRec and a property string named ORMRecField. Adjust the changes to the unit interposer_class: Please review carefully before make the needed changes.
unit interposer_class;
interface
uses Vcl.Forms, Vcl.Controls, CommCtrl, Messages, sPanel, sEdit, sPageControl, System.Classes, AdvCGrid, Uni, pixel_classes, ORM_utils;
{$TYPEINFO ON}
type TForm = class(Vcl.Forms.TForm) protected procedure CreateParams(var Params: TCreateParams); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; end;
TsPanel = class(sPanel.TsPanel) protected procedure CreateParams(var Params: TCreateParams); override; end;
TsEdit = class(sEdit.TsEdit) protected procedure CreateParams(var Params: TCreateParams); override; end;
TsPageControl = class(sPageControl.TsPageControl) protected procedure CreateParams(var Params: TCreateParams); override; private procedure TCMAdjustRect(var Msg: TMessage); message TCM_ADJUSTRECT; end;
TAdvColumnGrid = class(AdvCGrid.TAdvColumnGrid) private FByPassAF: TArray; function GetCellz(ACol, ARow: Integer): TZString; procedure SetCellz(ACol, ARow: Integer; const Value: TZString); function GetBypassAF(ACol: Integer): Boolean; procedure SetBypassAF(ACol: Integer; const Value: Boolean); protected procedure CreateParams(var Params: TCreateParams); override; public property Cellz[ACol, ARow: Integer]: TZString read GetCellz write SetCellz; property BypassAutoFit[ACol: Integer]: Boolean read GetBypassAF write SetBypassAF; published function CriaLinhaObjeto(MyObject: TObject): Integer; function CriaLinha: Integer; function GetColumnIndexByName(const nome: string): Integer; procedure SetBasicColumnConfig; end;
implementation
uses pixel_utils, System.Math, System.Types, Windows, System.SysUtils, TypInfo, Generics.Collections, Data.DB, Vcl.Graphics, ComCtrls, Vcl.Grids;
procedure TForm.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); StrPCopy(Params.WinClassName, 'ZPro'); end;
constructor TForm.Create(AOwner: TComponent); begin inherited; end;
destructor TForm.Destroy; begin inherited; end;
procedure TsPanel.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); StrPCopy(Params.WinClassName, 'Painel'); end;
procedure TsEdit.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); StrPCopy(Params.WinClassName, 'Editor'); end;
procedure TsPageControl.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); StrPCopy(Params.WinClassName, 'PagCtrl'); end;
procedure TsPageControl.TCMAdjustRect(var Msg: TMessage); begin inherited; case TabPosition of tpTop: begin PRect(Msg.LParam)^.Left:= 0; PRect(Msg.LParam)^.Right:= ClientWidth; PRect(Msg.LParam)^.Bottom:= ClientHeight;
- Assistant
- User
give me the full unit, without gaps
- Assistant
- User
[dcc32 Error] interposer_class.pas(13): E2599 Field definition not allowed in helper type
- Assistant
- User
Now I want a function so in a TForm, giving a TQryRecInfo instance and a field name, it returns the corresponding TComponent
- Assistant
- User
Adjust the unit so it uses a Dictionary to efficiently locate the Tcomponent. Ajust the unit code where needed
- Assistant
- User
This code snippet is showing compiler errors: Please review the unit carefully and make sure that the code is compilable using the latest Delphi compilers:
function TORMKey.Equals(const Other: TORMKey): Boolean; begin Result := (ORMRec = Other.ORMRec) and (FieldName = Other.FieldName); end;
function TORMKey.GetHashCode: Integer; begin Result := Integer(ORMRec) xor HashName(FieldName); end;
- Assistant
- User
The same code snippet is giving compiler errors: [dcc32 Error] interposer_class.pas(90): E2003 Undeclared identifier: 'Equals'
function TORMKey.Equals(const Other: TORMKey): Boolean; begin Result := (ORMRec = Other.ORMRec) and (FieldName = Other.FieldName); end;
function TORMKey.GetHashCode: Integer; begin Result := Integer(NativeInt(ORMRec)) xor HashOf(FieldName); end;
- Assistant
- User
There is a compiler hint:
[dcc32 Warning] interposer_class.pas(87): W1000 Symbol 'BobJenkinsHash' is deprecated: 'Use System.Hash.THashBobJenkins.GetHashValue'
- Assistant
- User
Give me a concrete example os this unit usage
- Assistant
- User
make adjutsments to the unit interposer_class so RegisterORMComponent takes all the needed parameters for the registration ( the TComponent, ORMRec and FieldName )
- Assistant
- User
now recreate the usage example (both the .pas and the .dfm files)
- Assistant
- User
change the interposer_class so you can just read ORMRec and ORMRecFieldInfo , and not write directly to them (write just through RegisterORMComponent) additionaly write a procedure UnRegisterORMComponent
- Assistant
- User
enhance the unit interposer_class so we can use case-insensitive fieldname search
- Assistant
- User
Now enchance the interposer_class unit using RTTI so it has an additional method to RegisterORMComponent so all the TComponents that have a matching Hint property of a published TQryRecInfo instance will be registered with the matching fieldname and the specified TQryRecInfo instance
- Assistant
- User
if Component.Hint does not exist. Use something like this:
uses RTTI;
var Context: TRttiContext; RttiType: TRttiType; RttiProperty: TRttiProperty; Comp: TComponent; HintValue: TValue; begin Comp := FindComponent('Button1'); RttiType := Context.GetType(Comp.ClassType); RttiProperty := RttiType.GetProperty('Hint');
if Assigned(RttiProperty) then begin HintValue := RttiProperty.GetValue(Comp); ShowMessage(HintValue.AsString); end else begin ShowMessage('The component does not have a Hint property.'); end; end;
- Assistant
- User
in RegisterComponentsByHint use TQryRecInfo property names, and not field names. Also compare Hint and TQryRecInfo property name in case-insensitive way
- Assistant