Search code examples
delphiconfigurationdelphi-2010enumerationini

Is it possible to typcast TFormBorderStyle property to Integer and vise versa?


It looks like I could use the RTTI to convert the enumerated type of a TFormBorderStyle property to String ans store it in my IniFile, and vise versa. However, I assumed I could typecast it back and forth from integer as well, but it does not seem to work. Why?

var
 Border: Integer = 3; 

procedure TfrmMain.FormCreate(Sender: TObject);
begin
 BorderStyle:= TFormBorderStyle(Border);
 pnlHeader.Visible:= ShowHeader;
 btnConfigure.Visible:= Configure;
 pnlFooter.Visible:= ShowFooter;
end;

Solution

  • Use Ord(bsDialog) to convert to an integer, and TBorderStyle(integervalue) to get back from integer.

    IniFile.WriteInteger('YourForm', 'Border', Ord(YourForm.BorderStyle));
    ...
    YourForm.BorderStyle := TFormBorderStyle(IniFile.ReadInteger('YourForm', 'Border', 0));