AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Rtti und Enum problem

Ein Thema von KodeZwerg · begonnen am 13. Aug 2022 · letzter Beitrag vom 13. Aug 2022
 
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.691 Beiträge
 
Delphi 11 Alexandria
 
#4

AW: Rtti und Enum problem

  Alt 13. Aug 2022, 22:15
Delphi-Quellcode:
  SetProperty(Panel1, 'Alignment', TValue.From<TAlignment>(taCenter));
  SetProperty(Panel1, 'BorderStyle', TValue.From<TBorderStyle>(bsSingle));
Vielen Dank aber das Resultat bleibt gerade das gleich, es mag an mir liegen deshalb zeige ich etwas ausführlicher wie ich es falsch mach

Delphi-Quellcode:
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.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:24 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz