Autor Beitrag
Spurius
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 142

Win XP Home
D3 Prof, D7 Prof
BeitragVerfasst: Do 10.07.03 16:47 
Hallo
ich möchte einer variablen(string) den wert aus einem editfeld übergeben.
Mit
variable := edit1.text funktioniert es nicht, da ich die variable später nicht in einem label als caption ausgeben kann.
Weiss vielleicht jemand woran das liegen könnte?
mfg
Spurius
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 10.07.03 17:14 
Hallo,

poste bitte mal ein wenig Code, damit wir uns ein genaueres Bild machen können.

Gruß
Klabautermann
Terra23
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 872

Win 8
Delphi 7
BeitragVerfasst: Do 10.07.03 17:18 
Also wenn du einer String-Variablen einen Text von einem Edit-Feld geben kannst, kannst du auch den Wert der Variablen als Caption in einem Label ausgeben. Wenn ich mich irre, schrei "halt" und beweise mir das Gegenteil:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);
var Text: String;
begin
Text:=Edit1.Text;
Label1.Caption:=Text;
end;


:-)

_________________
Hasta La Victoria Siempre
Spurius Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 142

Win XP Home
D3 Prof, D7 Prof
BeitragVerfasst: Do 10.07.03 17:19 
hallo
hier der code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  test:string;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
test := edit1.Text;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 label1.caption := test;
end;

end.

mfg
Spurius

Moderiert von user profile iconKlabautermann: Delphi Tags hinzugefügt.
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 10.07.03 17:36 
Hallo,

du führst die Zeile:
ausblenden Delphi-Quelltext
1:
test := edit1.Text;					

bei Programmstart aus. Damit kopierst du zu diesem im Edit Feld stehenden Text in die Variable. Wenn der Wert des Edit Feldes geändert wird, wird nicht Automatisch die Variable geändert.
Um dies zu erreichen musst du sie Zu dem Zeitpunkt aufrufen wo du den Wert haben willst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.Button1Click(Sender: TObject); 
begin 
 test := edit1.Text;
 label1.caption := test; 
end;


Wenn du die Variable nur dafür brauchst um den Text auszugeben dann kannst du sie auch wegoptimieren:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject); 
begin 
 label1.caption := edit1.Text; 
end;


Gruß
Klabautermann