I have to move a file in the system32 folder, I used this code:
//-----------FUNCTION----------------
function GetWindowsSystemDir(): String;
var
vlBuff: Array[0..MAX_PATH-1] of Char;
begin
getSystemDirectory(vlBuff, MAX_PATH);
Result := vlBuff;
end;
//-----------------------------------
const
SMyFile = GetWindowsSystemDir+'\intructions.txt'; //error here, line 87
var
S: TStringList;
begin
S := TStringList.Create;
try
S.Add('intructions');
S.SaveToFile(SMyFile);
finally
S.Free;
end;
end;
gives me error when compiling:
[DCC Error] Unit1.pas(87): E2026 Constant expression expected
Thanks.
As the compiler error message indicates, it expects a constant expression where you're initializing the const. But you're calling a function there, and the compiler won't evaluate it at compile time.
Declare a variable instead, and assign it inside the regular begin-end block of your code:
var
SMyFile: string;
S: TStringList;
begin
S := TStringList.Create;
try
S.Add('intructions');
SMyFile := GetWindowsSystemDir+'\intructions.txt';
S.SaveToFile(SMyFile);
finally
S.Free;
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With