Reputation: 13
I'm trying to make log with in sdl and i need to write time. Text must be pointer.
date //pointer
:=
DateTimeToStr(Now);// AnsiString
Here date is pointer and DateTimeToStr(Now) returns AnsiString and compiler stops there. How to fix it?
Upvotes: 1
Views: 2595
Reputation: 125757
The solution is to use PChar
, which is pointer to Char
.
var
str: AnsiString;
pDateStr: PChar;
...
str := DateTimeToStr(Now);
pDateStr := PChar(str);
// Do whatever you want with the PChar pDateStr
Upvotes: 0
Reputation: 199
I'm going to assume you are using either Delphi or FreePascal. Your current code will give you an Incompatible Types
error. You need to assign the result of DateTimeToStr(Now)
to a string and assign your pointer to the address of that string. Here is an example.
procedure ShowDateTime;
var
date: ^AnsiString;
str: AnsiString;
begin
str := DateTimeToStr(Now);
date := @str;
Writeln(date^);
end;
Read how to use pointers in Delphi or FreePascal.
Upvotes: 2