Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TDateTime -> Variant -> string -> Variant -> TDateTime (Exception!!)

306 views
Skip to first unread message

devel

unread,
Sep 5, 2003, 3:07:03 PM9/5/03
to
procedure TForm1.Button1Click(Sender: TObject);
var
d: TDateTime;
v: Variant;
s: string;
begin
d := Date; // d := 2003-01-31
v := d; // v := 2003-01-31
s := v; // s := '2003-01-31' // Delphi uses DateToStr function,
because v is *varDate*
v := s; // v := '2003-01-31'
d := v; // d := EXCEPTION!!! // Delphi does not use StrToDate
function!!! *Why?*
// "Could not convert variant of type (String) into type (Double)"

ShowMessage(FormatDateTime('yyyy-mm-dd', d));
end;

Delphi does not use StrToDate function! Why?

Thanks.


Finn Tolderlund

unread,
Sep 5, 2003, 4:17:28 PM9/5/03
to
"devel" <rom...@phoebus.com.br> skrev i en meddelelse
news:3f58...@newsgroups.borland.com...

> s := v; // s := '2003-01-31' // Delphi uses DateToStr function,
> because v is *varDate*
> v := s; // v := '2003-01-31'

V is a now a string.

> d := v; // d := EXCEPTION!!! // Delphi does not use StrToDate
> function!!! *Why?*
> // "Could not convert variant of type (String) into type (Double)"

You can't assign a string to TDateTime.
--
Finn Tolderlund

devel

unread,
Sep 5, 2003, 4:56:25 PM9/5/03
to
But the same code changing "d: TDateTime" to "d: Double", runs correctly!!

Ping Kam

unread,
Sep 5, 2003, 7:03:54 PM9/5/03
to
"devel" <deve...@phoebus.com.br> wrote in message
news:3f58f895$1...@newsgroups.borland.com...

> But the same code changing "d: TDateTime" to "d: Double", runs correctly!!
>
TDateTime and Double basically is the same thing.

Ping Kam

Finn Tolderlund

unread,
Sep 6, 2003, 4:29:15 AM9/6/03
to

"Ping Kam" <pk...@quikcard.com> skrev i en meddelelse
news:3f59...@newsgroups.borland.com...

Not just basically. They are exactly the same.
In the System unit you can see the deifinition:
TDateTime = type Double;
--
Finn Tolderlund

Ping Kam

unread,
Sep 6, 2003, 3:48:27 PM9/6/03
to
"Finn Tolderlund" <n...@spam.dk> wrote in message
news:3f59...@newsgroups.borland.com...
From the compilers perspective, they are different types and are not totally
compatible.

Type
TMyObject = class
private
FValue: Double;
public
property AsDouble: Double read FValue write FValue; // No error
property AsDateTime: TDateTime read FValue write FValue; //
Incompatible types: 'Double' and 'TDateTime'
end;

I would have agreed with you when the compiler stops complaining.

Ping Kam

Finn Tolderlund

unread,
Sep 6, 2003, 4:50:44 PM9/6/03
to
I wasn't talking about the compiler.
From a binary point of view they are the same.
--
Finn Tolderlund


"Ping Kam" <pk...@quikcard.com> skrev i en meddelelse

news:3f5a...@newsgroups.borland.com...

Ping Kam

unread,
Sep 6, 2003, 5:35:02 PM9/6/03
to
"Finn Tolderlund" <n...@spam.dk> wrote in message
news:3f5a...@newsgroups.borland.com...

> I wasn't talking about the compiler.
> From a binary point of view they are the same.
> --
Then I am right because I am talking from the compiler POV. You can't
change the context of my statement and claim I am incorrect.

Ping Kam

Finn Tolderlund

unread,
Sep 7, 2003, 3:15:27 AM9/7/03
to
I never said you're incorrect.
DO NOT claim I said something I didn't.
It's a very rude way of discussing.
--
Finn Tolderlund


"Ping Kam" <pk...@quikcard.com> skrev i en meddelelse

news:3f5a516b$1...@newsgroups.borland.com...

Ping Kam

unread,
Sep 7, 2003, 12:11:03 PM9/7/03
to
"Finn Tolderlund" <n...@spam.dk> wrote in message
news:3f5a...@newsgroups.borland.com...
> I never said you're incorrect.
> DO NOT claim I said something I didn't.
> It's a very rude way of discussing.
I apologise if that offends you. I didn't mean to be rude and I didn't know
that is. I will be more careful in the future.

However, that is exactly how I feel when I read your reply 'Not just
basically. They are exactly the same.'.

Ping Kam

Finn Tolderlund

unread,
Sep 7, 2003, 12:24:13 PM9/7/03
to
I don't care what you feel or not feel.
I did not write that you are incorrect, so do not say I did.
--
Finn Tolderlund


"Ping Kam" <pk...@quikcard.com> skrev i en meddelelse

news:3f5b...@newsgroups.borland.com...

Ping Kam

unread,
Sep 7, 2003, 1:07:36 PM9/7/03
to
"Finn Tolderlund" <n...@spam.dk> wrote in message
news:3f5b...@newsgroups.borland.com...

> I don't care what you feel or not feel.
> I did not write that you are incorrect, so do not say I did.
> --
Sorry. I aplogise again. And I admit that you didn't say I am incorrect.

Ping Kam

Finn Tolderlund

unread,
Sep 8, 2003, 1:27:04 AM9/8/03
to
Thanks, that's all I wanted to hear.
--
Finn Tolderlund


"Ping Kam" <pk...@quikcard.com> skrev i en meddelelse

news:3f5b643c$1...@newsgroups.borland.com...

0 new messages