unit Unit26;
interface
uses
System.TypInfo, System.Rtti,
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls;
type
TForm26 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form26: TForm26;
implementation
{$R *.dfm}
function SetProperty(
const AControl: TControl;
const AProperty:
string;
const AValue: TValue): Boolean;
var
LControl: TControl;
LRttiContext: TRttiContext;
LRttiProperty: TRttiProperty;
begin
Result := False;
LControl := AControl;
LRttiProperty := LRttiContext.GetType(LControl.ClassType).GetProperty(AProperty);
if ((LRttiProperty <>
nil)
and (LRttiProperty.Visibility
in [mvPrivate, mvProtected, mvPublic, mvPublished]))
then
begin
LRttiProperty.SetValue(LControl, AValue);
Result := True;
end;
end;
function CreateControl(
const AOwner: TComponent;
const AParent: TWinControl; AClass: TControlClass): Boolean;
type
TFormBorderStyle = (bsNone, bsSingle, bsSizeable, bsDialog, bsToolWindow, bsSizeToolWin);
TBorderStyle = bsNone..bsSingle;
TAlignment = (taLeftJustify, taRightJustify, taCenter);
var
i, ii: Integer;
LControl: TControl;
begin
Result := False;
LControl := AClass.Create(AOwner);
try
LControl.Parent := AParent;
LControl.Visible := False;
LControl.Enabled := False;
SetProperty(LControl, '
ReadOnly', True);
LControl.Width := 200;
LControl.Left := High(Integer);
SetProperty(LControl, '
Alignment', TValue.From<TAlignment>(taCenter));
// typecast error
SetProperty(LControl, '
BorderStyle', TValue.From<TBorderStyle>(bsSingle));
// typecast error
LControl.Align := alLeft;
SetProperty(LControl, '
MaxLength', 1);
SetProperty(LControl, '
Color', clWhite);
SetProperty(LControl, '
Text', '
X');
SetProperty(LControl, '
Caption', '
Y');
finally
Result := True;
end;
end;
procedure TForm26.Button1Click(Sender: TObject);
begin
CreateControl(Form26, Form26, TEdit);
end;
end.