Autor Beitrag
Ruachel
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 13:54 
Hallo zusammen,

Ich bin neu in diesem Forum, und auch ein Neuling in Delphi. :oops:

Ich bin zwar in Programmerstellung kein Neuling, (verdien mit SPS-Programmierung meine Brötchen), hab auch vor ca. 10 Jahren mit TurboPascal 7.0 rumgespielt, die Funktionsvielfalt von Delphi erschlägt mich aber fast.

Seit 2 Tagen versuche ich nun mich Delphi anzunähern. Es geht zähe aber doch voran, jetzt hänge ich allerdings an einer Stelle, an der ich nicht weiterkomme:

Ich möchte aus Form1 ein neues Fenster Form2 öffnen, habe über dieses Thema stundenlang Tutorials gewälzt und in Foren gestöbert, bin auch einem Tutorial gefolgt, aber ohne Erfolg. :cry:

hier meine unit1:

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:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ShellTreeView1: TShellTreeView;
    ShellListView1: TShellListView;
    Label1: TLabel;
    Label2: TLabel;
    Button2: TButton;
    Label5: TLabel;
    Button1: TButton;
    procedure ShellListView1AddFolder(Sender: TObject;
      AFolder: TShellFolder; var CanAdd: Boolean);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

 uses unit2;
{$R *.dfm}

procedure TForm1.ShellListView1AddFolder(Sender: TObject;
  AFolder: TShellFolder; var CanAdd: Boolean);
  var XExt: string;

begin   
XExt := ExtractFileExt(AFolder.PathName);
if XExt = '.txt'
then CanAdd := true
else CanAdd := false;
end;

procedure TForm1.Button2Click(Sender: TObject);
Var
infile: Textfile;
pfad_file_original:string ;
outfile: Textfile;
lese, schreibe: string;
begin
 try
  Label5.Caption := ShellListView1.SelectedFolder.PathName;
except
  raise Exception.Create('Bitte Datei wählen!');
end;
pfad_file_original:=ShellListView1.SelectedFolder.PathName;
  Assignfile(infile, pfad_file_original);
  AssignFile(outfile, 'c:\ziel.txt');
  Reset(infile);
  Rewrite(outfile);
  while not Eof(infile) do
  begin
     ReadLn(infile,lese);
     schreibe:=lese;
     WriteLn(outfile,schreibe);
  end;

   closefile(outfile);
   closefile(infile);
end;     

procedure TForm1.Button1Click(Sender: TObject);

begin
  Form2.ShowModal;   (*<---hier hakt`s)  *)
end;

end.


Wenn ich in Zeile 78 "Form2.ShowModal" verwende, gibts eine exception "cannot make a visible window modale"

Wenn ich stattdessen "Form2.Show" verwende, wird Form2 zwar angezeigt, kann aber nicht mehr geschlossen werden, weder durch "x" noch durch button1Click in Form2.

hier die unit2:

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:
unit Unit2;

interface

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

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
self.close; (*<--- hier hakt´s *)
end;

end.


Wenn ich statt "self.close" "Form2.close" gehts auch net.

Das ist nur ein Übungsprogramm, um ein "Gefühl" für die Funktionsweise von Delphi zu bekommen, es verfolgt noch keinen bestimmten Zweck.

In unit1 habe ich es immerhin geschafft, eine Datei zeilenweise einzulesen und auch wieder zeilenweise rauszuschreiben *stolzbin* :wink:

Ich würde Euch bitten das mal durchzusehen, mit meinem Wissensstand komm´ ich nicht weiter.

Danke schonmal im voraus

greetz

R.

Moderiert von user profile iconTino: Überflüssige Zeilenumbrüche entfernt.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 24.08.05 14:02 
Zitat:
Wenn ich in Zeile 78 "Form2.ShowModal" verwende,
gibts eine exception "cannot make a visible window modale"

Die Exception kommt nur wenn das Fenster schon geöffnet ist. Welches Formular isn dein Hauptformular -> Das, welches beim Programmstart angezeigt wird.
Ruachel Threadstarter
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 14:16 
Tja, natürlich form1

Ein Formular aus sich selbst aufzurufen hätte doch wenig Sinn oder? :wink:

oder könnte das Form2 schon von wo anders her aufgerufen worden sein?

Zumindest habe ich dafür nirgends eine Prozedur drinnen.

Und das ganze Prog. besteht nur aus den 2 units. :(

hmmmm....

R.
espen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90
Erhaltene Danke: 1


D6 Prof./D7 Prof. MSSQL, MySQL
BeitragVerfasst: Mi 24.08.05 14:27 
Hi,

wie sieht denn Deine Projektdatei aus ?
Die sollte ungefähr so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
program Project1;

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

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

mit [Strg.]+[F12] kann Du die units anzeigen und dann die Project1-unit öffnen.
Tilo
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 1098
Erhaltene Danke: 13

Win7 geg. WInXP oder sogar Win98
Rad2007
BeitragVerfasst: Mi 24.08.05 14:31 
Probier mal:
Menüleiste, Projekt, Dem Projekt hinzufügen
Im folgenden Dialog dann deine Unit2.pas auswählen und öffnen.

kleiner Hinweis am Rande: Falls Du eingeschränkte rechte hast, vorher abspeichern, sonst kann es auch Fehler geben.

@Espen
stimmt schon nur wie hilft him das? Nach mein Tipp steht dann:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.


Und dann funktioniert es.
Ruachel Threadstarter
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 14:42 
Danke für Euer Interessse,

@espen: die Projektdatei:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
program Konverter;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1},
  Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.CreateForm(TForm2, Form2);
  Application.Run;
end.



@tilo:

Hab´ich gemacht, obwohl ich den Sinn nicht ganz versteh´
Die unit2 ist in der Projectdatei eingetragen, und auch in der uses clausel von unit1....


R.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 24.08.05 15:13 
Kannst du mir mal das ganz Projekt zum downloaden schicken, ich geh's mal durch.
Ruachel Threadstarter
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 15:33 
Ja danke,

ich hab auch schon gechect, ob die Eigenschaft "visible" von Form2 vielleicht auf
true steht, is aber nicht.


R.
Einloggen, um Attachments anzusehen!
Carnivean
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 36

Win 2000, Win Xp Prof
D3 Prof, D7 Prof, D2005 Pers
BeitragVerfasst: Mi 24.08.05 15:40 
Fehler gefunden :)

Setz mal Enabled der Form2 auf true ;)

Entweder im ObjectInspector oder so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);

begin
  Form2.Enabled := true;
  Form2.ShowModal;   (*<---hier hakt`s  *)
end;


Gruß
Carni
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mi 24.08.05 15:44 
Hast du's auch kompiliert und kannst dsa mit sicherheit sagen? Irgendwie kommt mir das komisch vor..

//Edit: Ok, ok es lag wirklich daran. :wink:


Zuletzt bearbeitet von Fabian W. am Mi 24.08.05 15:49, insgesamt 1-mal bearbeitet
Carnivean
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 36

Win 2000, Win Xp Prof
D3 Prof, D7 Prof, D2005 Pers
BeitragVerfasst: Mi 24.08.05 15:48 
Ja hab ich natürlich, bei mir funktioniert es so.

Hab mal eben aus Spass nen neues Projekt gemacht, indem ich nur die Form.Enabled auf false gesetzt habe, sie wird zwar angezeigt aber man kann sie nicht schliessen etc. Sie reagiert eben auf keinerlei Eingaben, egal ob Maus, Tastatur oder Timer, und genau das macht Enabled. Also eigentlich logisch :).

Gruß
Carni
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 24.08.05 15:48 
stell mal form2.enabled wieder auf true, dann funktionierts mit show wie es sollte

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Ruachel Threadstarter
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 15:59 
Hallo Leute,

ja, problem gelöst, scheint sich um einen "Newbie-Fehler" zu handeln :oops:

Aber wie gesagt, die Komplexität erschlägt mich fast, und
aller Anfang ist schwer.
Muss mich wohl näher mit dem Objektinspector befassen.
Is das nicht seltsam, dass bei einem Form, diese Eigenschaft defaultmäßig
auf false steht ? - Vielleicht hab ichs aber auch in der Hitze des Gefechts selbst umgestellt..wasweissich.

Herzlichen Dank an alle für die engagierte Hilfe

Hier wird man wirklich geholfen :wink:

R
Carnivean
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 36

Win 2000, Win Xp Prof
D3 Prof, D7 Prof, D2005 Pers
BeitragVerfasst: Mi 24.08.05 16:02 
Hast du 100% selbst umgestellt :), erstell einfach mal ein neues Projekt und guck, auf was Enabled der Form steht, bin mir sicher es wird auch bei dir auf true stehen.
Ruachel Threadstarter
Hält's aus hier
Beiträge: 14

Win XPpro SP2, WIN2000
D6 Pers
BeitragVerfasst: Mi 24.08.05 16:27 
jaja, hast recht, ich habs probiert

und....user defined image

gehört aber zum Lernprozess..den Fehler mach i sicher nimmer :wink:

grüsse


R.