Old School: Delphi for .Net Step-by-Step Example
In this old-school Delphi for .Net example (before Delphi Prism), notice that you can use global functions and procedures. This was changed with Prism where everything is within a class.
1. Add SysUtils to the uses clause so we can use the VCL.Net IntToStr command.
interface
uses
System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data, Borland.Vcl.SysUtils;
2. Also in the interface section, prototype our two custom routines.
type
//...default form class code here.
procedure SayHello(pName: String);
function Add(a, b : Integer) : integer;
3. Add the two custom routines to the implementation section.
implementation
//...Delphi generated code here.
procedure SayHello(pName: String);
begin
MessageBox.Show('Hello ' + pName);
end;
function Add(a, b : Integer) : integer;
begin
result := a + b;
end;
end.
4. Call the two custom routines from a button click event:
procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);
begin
SayHello('Mike');
MessageBox.Show(IntToStr(Add(3, 4)));
end;