[Delphi]Delphi学习

procedure TForm1.btn1Click(Sender: TObject);
var
  tmp: Integer;
begin
  tmp := StrToInt(edt1.Text);
  if (tmp mod 2 = 0) then
  begin
    MessageBox(0, PAnsiChar(IntToStr(tmp)+' 为偶数'), '提示', MB_OK)
  end
  else
  begin
     MessageBox(0, PAnsiChar(IntToStr(tmp)+' 为奇数'), '提示', MB_OK)
  end;


end;

 //判断奇数偶数

procedure TForm1.btn1Click(Sender: TObject);
var
  tmp: Integer;
begin
  tmp := StrToInt(edt1.Text)+StrToInt(edt2.Text);
  edt3.Text := IntToStr(tmp);
end;
//把两数相加并把结果放到第三个文本框内
procedure TForm1.btn1Click(Sender: TObject);
var
  tmp: Double;
begin
  tmp := StrToFloat(edt1.Text)+StrToFloat(edt2.Text);
  edt3.Text :=   FloatToStr(tmp);


end;
//上面的只能计算整数 这个可以计算小数
//double 转 stringstring 转 double
//自定义函数 返回两个数字中较大的
function Max(x, y: Real): Real;
begin
  if x > y then result := x
  else result := y;
end;


//注意   if x > y then result := x 后不能有 ; 号

 DLL窗体

//----------------------dpr 部分
library  Project1;

uses
  Forms,
  DllFormUnit in 'DllFormUnit.pas' {Form1};

{$R *.res}
exports
UppTolow;
end.
//----------------------------pas部分
unit DllFormUnit;

interface

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

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
 function UppToLow: Boolean; stdcall;
implementation

{$R *.dfm}

function UppToLow: Boolean;
var   Form1: TForm1;
begin
  result:=False;
  Form1:=TForm1.Create(Application);
    Form1.ShowModal;
end;

end.
//----------------------------调用声明
function UppToLow:Boolean;stdcall external 'Project1.dll';
implementation

{$R *.dfm}
//----------------------------按钮调用

procedure TMainForm.btn2Click(Sender: TObject);
begin
  UppToLow;
end;
//DLL自动呼出窗体

library  Project1;

uses
  Forms,
  DllFormUnit in 'DllFormUnit.pas' {Form1};

{$R *.res}
exports
UppTolow;
begin
    UppTolow;
end.
//DLL编写
library Test;


uses
  SysUtils,
  Classes,
  Dialogs;


function Test11(a, b: integer): integer;
begin
  Result := a + b;
  ShowMessage('Test11函数调用');
end;




exports
  Test11;
begin
    ShowMessage('DLL启动函数调用');
end.
//Delphi调用汇编指令
procedure sitCall();stdcall;
begin
 //// [[[[[95E800+1c]+24]+918]+14]+1c ]
 asm
  push 1
  mov ecx,$95E800
  add ecx,$1C
  mov ecx,[ecx] // ecx=Pointer(ecx^)
  add ecx,$24    // ecx=ecx+$24
  mov ecx,[ecx]
  add ecx,$918
  mov ecx,[ecx]
  add ecx,$14
  mov ecx,[ecx]
  add ecx,$1C
  mov ecx,[ecx]
  mov ebx,$452b20
  call ebx
  end;

end;
原文地址:https://www.cnblogs.com/Wzqa/p/3093497.html