...change the value of Constants?
Author: Thomas Weidenmueller
procedure ChangeConst(const Constant; var Value; Size: Integer);
begin
Move((@Value)^, (@Constant)^, Size);
end;
// How to use ChangeConst: (Sample)
const
TestStrConst: string = 'This is a text sample';
TestInteger: Integer = 4367;
var
NewString: string;
NewInteger: Integer;
begin
// String Demo:
ShowMessage('Before ChangeStringConst (TestStrConst): ' + TestStrConst);
NewString := 'New Value';
ChangeConst(TestStrConst, NewString, SizeOf(string));
ShowMessage('After ChangeStringConst (TestStrConst): ' + TestStrConst);
// Integer Demo:
ShowMessage('Before ChangeStringConst (TestInteger): ' + IntToStr(TestInteger));
NewInteger := 93534;
ChangeConst(TestInteger, NewInteger, SizeOf(Integer));
ShowMessage('After ChangeStringConst (TestInteger): ' + IntToStr(TestInteger));
end;
printed from
www.swissdelphicenter.ch
developers knowledge base