Entry
Delphi: Constant: Convert: String: How to cast a string to a constant? [shortstring / MethodAddress]
Feb 24th, 2004 19:47
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 25 February 2004 - 04:40 am -------------------
Delphi: Constant: Convert: String: How to cast a string to a constant?
[shortstring / MethodAddress]
---
---
Method: parameter passing and using shortstring and a constant string
parameter
---
Steps: Overview:
1. -Create a new application
2. -Put a button on the form
3. -Fill in the following code
--- cut here ---------------------------------------------------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure PROCTest1;
procedure PROCTest2( const s : string );
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.PROCTest1;
var s : shortstring;
begin
s := 'mystring'; // e.g. input this from a data file
PROCTest2( s );
end;
procedure TForm1.PROCTest2( const s : string );
begin
ShowMessage( 'here ' + s + ' is a constant string' );
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
PROCTest1;
end;
end.
--- cut here ---------------------------------------------------------
4. -Run the code
That will show a dialog box:
[here mystring is a constant string]
----------------------------------------------------------------------