我在TSystemTime中遇到了这样的问题! Delphi 7中有一个很好的项目!我将此程序翻译为Android,因此选择权在Lazarus上,因为它可以在我需要的平台下进行编程。
当我开始在Android上运行程序时,编译器开始在Windows.pas上使用它。我完全看到了它,然后在项目中添加了我需要的类型,常量,过程,函数,这里最有趣的事情开始了……
以下是错误所在的代码部分:
function NowUTC: TDateTime;
var
st: TSystemTime;
begin
Uninit(st);
GetSystemTime(st);
result := SystemTimeToDateTime(st); //error
end;
function UtcToLocal(utcTime: TDateTime): TDateTime;
var
st: TSystemTime;
lt: TSystemTime;
begin
DateTimeToSystemTime(utcTime, st); <- error
Uninit(lt);
SystemTimeToTzSpecificLocalTime(nil, st, lt);
result := SystemTimeToDateTime(lt); <- error
end;
function LocalToUTC(localTime: TDateTime): TDateTime;
var
inverseTZ: TTimeZoneInformation;
st: TSystemTime;
ut: TSystemTime;
begin
DateTimeToSystemTime(localTime, st); <- error
Uninit(inverseTZ);
GetTimezoneInformation(inverseTZ);
inverseTZ.Bias := -inverseTZ.Bias;
inverseTZ.DaylightBias := -inverseTZ.DaylightBias;
Uninit(ut);
SystemTimeToTzSpecificLocalTime(@inverseTZ, st, ut);
result := SystemTimeToDateTime(ut); <- error
end;
function UtcDateTimeToFiletime(utcDateTime: TDateTime): TFileTime;
var
st: TSystemTime;
begin
DateTimeToSystemTime(utcDateTime, st); <- error
Uninit(result);
SystemTimeToFileTime(st, result);
end;
function FileTimeToLocalDateTime(const ft: TFileTime): TDateTime;
var
st: TSystemTime;
lft: TFileTime;
begin
Uninit(lft);
FileTimeToLocalFileTime(ft, lft);
Uninit(st);
FileTimeToSystemTime(lft, st);
result := SystemTimeToDateTime(st); <- error
end;
编译器显示此类错误:
Error: (4025) Incompatible type for arg no. 1: Got "_SYSTEMTIME", expected "TSystemTime"
Error: (3069) Call by var for arg no. 2 has to match exactly: Got "_SYSTEMTIME" expected "TSystemTime"
Error: (4025) Incompatible type for arg no. 1: Got "_SYSTEMTIME", expected "TSystemTime"
Error: (3069) Call by var for arg no. 2 has to match exactly: Got "_SYSTEMTIME" expected "TSystemTime"
Error: (4025) Incompatible type for arg no. 1: Got "_SYSTEMTIME", expected "TSystemTime"
Error: (3069) Call by var for arg no. 2 has to match exactly: Got "_SYSTEMTIME" expected "TSystemTime"
Error: (4025) Incompatible type for arg no. 1: Got "_SYSTEMTIME", expected "TSystemTime"
这是我使用的类型:
{TSystemTime}
{ System time is represented with the following structure: }
PSystemTime = ^TSystemTime;
_SYSTEMTIME = record
wYear: Word;
wMonth: Word;
wDayOfWeek: Word;
wDay: Word;
wHour: Word;
wMinute: Word;
wSecond: Word;
wMilliseconds: Word;
end;
{$EXTERNALSYM _SYSTEMTIME}
TSystemTime = _SYSTEMTIME;
SYSTEMTIME = _SYSTEMTIME;
{$EXTERNALSYM SYSTEMTIME}
在写入的类型上是相同的(TSystemTime = _SYSTEMTIME)帮助,请理解。好了,此外,我从Windows.pas获得的功能也可以帮助...
procedure GetSystemTime(var lpSystemTime: TSystemTime); stdcall;
{$EXTERNALSYM GetSystemTime}
procedure GetSystemTimeAsFileTime(var lpSystemTimeAsFileTime: TFileTime); stdcall;
{$EXTERNALSYM GetSystemTimeAsFileTime}
function SetSystemTime(const lpSystemTime: TSystemTime): BOOL; stdcall;
{$EXTERNALSYM SetSystemTime}
procedure GetLocalTime(var lpSystemTime: TSystemTime); stdcall;
{$EXTERNALSYM GetLocalTime}
function SetLocalTime(const lpSystemTime: TSystemTime): BOOL; stdcall;
{$EXTERNALSYM SetLocalTime}
function GetSystemTimeAdjustment(var lpTimeAdjustment, lpTimeIncrement: DWORD;
var lpTimeAdjustmentDisabled: BOOL): BOOL; stdcall;
{$EXTERNALSYM GetSystemTimeAdjustment}
function SystemTimeToTzSpecificLocalTime(lpTimeZoneInformation: PTimeZoneInformation;
var lpUniversalTime, lpLocalTime: TSystemTime): BOOL; stdcall;
{$EXTERNALSYM SystemTimeToTzSpecificLocalTime}
function GetTimeZoneInformation(var lpTimeZoneInformation: TTimeZoneInformation): DWORD; stdcall;
{$EXTERNALSYM GetTimeZoneInformation}
function SetTimeZoneInformation(const lpTimeZoneInformation: TTimeZoneInformation): BOOL; stdcall;
{$EXTERNALSYM SetTimeZoneInformation}
function SystemTimeToFileTime(const lpSystemTime: TSystemTime; var lpFileTime: TFileTime): BOOL; stdcall;
{$EXTERNALSYM SystemTimeToFileTime}
function FileTimeToLocalFileTime(const lpFileTime: TFileTime; var lpLocalFileTime: TFileTime): BOOL; stdcall;
{$EXTERNALSYM FileTimeToLocalFileTime}
function LocalFileTimeToFileTime(const lpLocalFileTime: TFileTime; var lpFileTime: TFileTime): BOOL; stdcall;
{$EXTERNALSYM LocalFileTimeToFileTime}
function FileTimeToSystemTime(const lpFileTime: TFileTime; var lpSystemTime: TSystemTime): BOOL; stdcall;
{$EXTERNALSYM FileTimeToSystemTime}
procedure OutputDebugString(lpOutputString: PChar); stdcall;
{$EXTERNALSYM OutputDebugString}
答案 0 :(得分:0)
您不会发布任何可编译的内容(缺少使用子句等),因此第一步将丢弃所有这些内容并将问题减少到最小程度。
但是,这就是说,如果您自己声明tsystemtime,然后将其传递给期望在Windows单元中声明类型的Windows单元例程,那么也就怪它不起作用了。