Re: WORKING WITH STRINGS ?! THE FINAL CHALLENGE !

From: Skybuck Flying (nospam_at_hotmail.com)
Date: 02/21/04


Date: Sat, 21 Feb 2004 04:43:30 +0100

Ok mister ROB, I will be TOTALY FAIR TO YOU

The previous posted example/code was VERY MESSY.

So therefore I have created a new example.

The idea is simple, the string should stay alive using the 'storage' pointer
and any other solution you can come up with.

*** begin of dfm ***
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 363
  Height = 155
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Label1: TLabel
    Left = 8
    Top = 16
    Width = 30
    Height = 13
    Caption = 'Text1:'
  end
  object Label2: TLabel
    Left = 8
    Top = 40
    Width = 30
    Height = 13
    Caption = 'Text2:'
  end
  object Edit1: TEdit
 Left = 48
    Top = 12
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
  end
  object Edit2: TEdit
    Left = 48
    Top = 36
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit2'
  end
  object Button1: TButton
    Left = 176
    Top = 10
    Width = 75
    Height = 25
    Caption = 'store string'
    TabOrder = 2
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 176
    Top = 34
    Width = 75
    Height = 25
 Caption = 'retrieve string'
    TabOrder = 3
    OnClick = Button2Click
  end
end

*** end of dfm ***

*** begin of unit ***

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
 Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
 { Public declarations }
 Storage : pointer;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
 Storage := Edit1.Text;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Edit2.Text := Storage;
end;

end.

*** end of unit ***


Quantcast