Recent

Author Topic: Converting to string TDate component palette of RTTI  (Read 4246 times)

andersonscinfo

  • Full Member
  • ***
  • Posts: 156
Converting to string TDate component palette of RTTI
« on: May 26, 2014, 11:43:57 pm »
Hello, it is my first test with the components of RTTI palette, I wanted to help convert TDate to String before passing the value to the TIEdit, is this possible?

Att
Anderson Junior

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Converting to string TDate component palette of RTTI
« Reply #1 on: May 27, 2014, 12:06:59 am »
DateToStr(Date).

andersonscinfo

  • Full Member
  • ***
  • Posts: 156
Re: Converting to string TDate component palette of RTTI
« Reply #2 on: May 27, 2014, 12:16:49 am »
Thanks for the reply, but I guess not concegui explain my problem, I'll try to be clearer with an example

Code: [Select]
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, RTTICtrls, Forms, Controls, Graphics, Dialogs,
  StdCtrls;

type

  { TMyObject }

  TMyObject = class(TObject)
  private
    FVDate: TDate;
  published
    property VDate: TDate read FVDate write FVDate;
  end;

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    TIEdit1: TTIEdit;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  VarDate: TMyObject;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
  VarDate:=TMyObject.Create;

  TIEdit1.Link.TIObject:=TPersistent(VarDate);
  TIEdit1.Link.TIPropertyName:='VDate';
end;

procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  VarDate.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  VarDate.VDate:=Now;
end;

end.


where to add the conversion?

not want to seem loose, but I do not concegui.

Att.
Anderson Junior

kapibara

  • Hero Member
  • *****
  • Posts: 656
Re: Converting to string TDate component palette of RTTI
« Reply #3 on: May 27, 2014, 01:58:57 am »
Is this what you look for:

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  VarDate.VDate:=Now;
  TIEdit1.Text:=DateToStr(VarDate.VDate);
end;
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

andersonscinfo

  • Full Member
  • ***
  • Posts: 156
Re: Converting to string TDate component palette of RTTI
« Reply #4 on: May 27, 2014, 04:01:32 am »
Hello, thanks for trying, but the component is TIEdit1 RTTI and he's mapped / hyperlinked, unfortunately this code you gave me does not work in this case, still not sure but I think he does not accept interaction unless the object to which this hyperlinked.

Att
Anderson Junior

kapibara

  • Hero Member
  • *****
  • Posts: 656
Re: Converting to string TDate component palette of RTTI
« Reply #5 on: May 29, 2014, 03:59:13 am »
Dont think you can cast a TObject to a TPersistent.

Perhaps:

    * Inherit TMyObject from TPersistent and skip the casting.

    * Create a TMyObject property that returns the string value of FVDate.

    * Assign that propertys name to TIPropertyName instead of VDate.

I made a small example that seems to work, attached.

(Or you could try making FVDate a string value instead of a TDate and read it directly without getters/setters)

« Last Edit: May 29, 2014, 04:45:31 am by kapibara »
Lazarus trunk / fpc 3.2.2 / Kubuntu 24.04 - 64 bit

andersonscinfo

  • Full Member
  • ***
  • Posts: 156
Re: Converting to string TDate component palette of RTTI
« Reply #6 on: May 29, 2014, 01:06:46 pm »
thanks, seems to be the only way out, I will follow his example, and switch to TPersistent, and create a property to return the value of vDate in string.

thanks again for your attention.

Att
Anderson Junior

 

TinyPortal © 2005-2018