首页  编辑  

改变常量变量的值

Tags: /超级猛料/Language.Object Pascal/在Delphi编程中使用C语言代码/   Date Created:

procedure ChangeConst ( const Constant ; var Value ; Size : Integer );

begin

 Move ((@ Value )^, (@ Constant )^, Size );

end ;

// How to use ChangeConst: (Sample)

procedure TForm1 . Button1Click ( Sender : TObject );

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 ;