Einzelnen Beitrag anzeigen

nanix
(Gast)

n/a Beiträge
 
#1

Calculate Min Max of integer

  Alt 2. Dez 2009, 21:55
Hello how could i calculate this ... i was fooling around but still can't get it working here is what i got so far.
Basicly all values are the same MIN MAX VALUE

Delphi-Quellcode:
unit Unit3;

interface

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

type
  TForm3 = class(TForm)

    Button1: TButton;
    Timer1: TTimer;
    Button2: TButton;


    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


 type
  TMyInt = record
    FValue: Integer;
    FMin: Integer;
    FMax: Integer;
    FInit: Boolean;
  private
    procedure SetValue(const IntValue: Integer);
  public
    procedure Init;

    property Value: Integer read FValue write SetValue;
    property Min: Integer read FMin;
    property Max: Integer read FMax;
    end;

var
  Form3: TForm3;







implementation
{$R *.dfm}

procedure TMyInt.Init;
begin
  FInit := False;
end;

procedure TMyInt.SetValue(const IntValue: Integer);
begin
  if FValue <> IntValue then
    FValue := IntValue;

  if not FInit then
  begin
    FMax := FValue;
    FMin := FValue;
    FInit := True;
  end
  else
  begin
    if FValue > FMax then
      FMax := FValue;
    if FValue < FMin then
      FMin := FValue;
  end;
end;

// usage


procedure TForm3.Timer1Timer(Sender: TObject);
var
  temp: TMyInt;
begin
  temp.Init;
  temp.Value:=Random(100);
  form3.Caption:='Value '+inttostr(Temp.Value)+' Min '+inttostr(temp.Min)+' Max '+inttostr(temp.Max);

end;

end.
  Mit Zitat antworten Zitat