unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } function Min(DataAry: array of Real): Real; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}function TForm1.Min(DataAry: array of Real): Real; var i: integer; begin if Length(DataAry) = 0 then begin Result := 0; exit; end; Result := DataAry[0]; for i := 1 to Length(DataAry) - 1 do if DataAry[i] < Result then Result := DataAry[i]; end;procedure TForm1.Button1Click(Sender: TObject); var MyAry: array[0..4] of Real; begin MyAry[0] := 5.1; MyAry[1] := 1; MyAry[2] := 3; MyAry[3] := 10; MyAry[4] := 0.8; ShowMessage('Min Is: ' + FloatToStr(Min(MyAry))); end;end.
用Math.MinValue uses Math;procedure TForm1.btn1Click(Sender: TObject); var val: Double; arrVal: array of Double; vals: TStringList; source: PChar; i: Integer; begin source := '5.1,1,3,10,0.8'; vals := TStringList.Create; ExtractStrings([','], [], source, vals); SetLength(arrVal, vals.Count); for i := 0 to vals.Count - 1 do arrVal[i] := StrToFloat(vals[i]); val := MinValue(arrVal); ShowMessage(FloatToStr(val)); end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function Min(DataAry: array of Real): Real;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function TForm1.Min(DataAry: array of Real): Real;
var
i: integer;
begin
if Length(DataAry) = 0 then
begin
Result := 0;
exit;
end; Result := DataAry[0];
for i := 1 to Length(DataAry) - 1 do
if DataAry[i] < Result then
Result := DataAry[i];
end;procedure TForm1.Button1Click(Sender: TObject);
var
MyAry: array[0..4] of Real;
begin
MyAry[0] := 5.1;
MyAry[1] := 1;
MyAry[2] := 3;
MyAry[3] := 10;
MyAry[4] := 0.8;
ShowMessage('Min Is: ' + FloatToStr(Min(MyAry)));
end;end.
uses Math;procedure TForm1.btn1Click(Sender: TObject);
var
val: Double;
arrVal: array of Double;
vals: TStringList;
source: PChar;
i: Integer;
begin
source := '5.1,1,3,10,0.8';
vals := TStringList.Create;
ExtractStrings([','], [], source, vals);
SetLength(arrVal, vals.Count);
for i := 0 to vals.Count - 1 do
arrVal[i] := StrToFloat(vals[i]);
val := MinValue(arrVal);
ShowMessage(FloatToStr(val));
end;
vals.Free;