Einzelnen Beitrag anzeigen

tiller

Registriert seit: 21. Jan 2008
23 Beiträge
 
Delphi 7 Personal
 
#27

Re: Edit-Felder während der Laufzeit erstellen... wie?

  Alt 22. Jan 2008, 10:02
Ein wahres Wort, sirius

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Button3: TButton;
    label_error: TLabel;
    Panel1: TPanel;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type TMatrix = array[1..10, 1..10] of Real;

var rows, lines, i, j: integer;

procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.width:=368;
Form1.Height:=95;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
rows:=strtoint(edit1.text);
lines:=strtoint(edit2.Text);
if ((lines>10) or (rows>10)) then label_error.Caption:='Matrix ist auf eine Größe von 10,10 limitiert. Eingaben wurden korrigiert.';
if rows>10 then
  begin
    edit1.text:='10';
    rows:=10;
  end;
if lines>10 then
  begin
    edit2.text:='10';
    lines:=10;
  end;
if rows>4 then Form1.width:=25+(rows+1)*(57+8);
Form1.Height:=110+lines*(21+8)-8;
for i:=1 to lines do
  begin
    for j:=1 to rows do
      begin
        with TEdit.create(Panel1) do //vorher 'owner' -> Form1
          begin
            Parent:=self;
            Left:=16+(j-1)*64;
            Top:=72+(i-1)*24;
            width:=57;
            Name:='e'+inttostr(j)+inttostr(i);
            //caption:='';
          end;
      end;
    with TEdit.create(Panel1) do
      begin
        Parent:=self;
        Left:=16+(j-1)*64;
        Top:=72+(i-1)*24;
        width:=57;
        Name:='l'+inttostr(i);
        //caption:='';
      end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
label_error.caption:='';
FreeAndNil(Panel1);
with TPanel.create(owner) do
  begin
    Parent:=self;
    Left:=280;
    Top:=40;
    width:=57;
    height:=25;
    Name:='Panel1';
    visible:=false;
  end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
label_error.Caption:='';
end;

end.
Hier mal der komplette Code. Das Ganze soll ein LGS nach dem Gaußschen Algorithmus lösen, allerdings Schritt für Schritt.

Button1 erzeugt die Matrix und den Lösungsvektor, Button2 soll das Programm resetten und Button 3 wird später immer einen Lösungsschritt durchführen.
  Mit Zitat antworten Zitat