| Autor |
Beitrag |
Hiob
Hält's aus hier
Beiträge: 12
|
Verfasst: Mi 01.12.04 22:27
Hi!
Ich bin neu und hoffe auf baldige Hilfe von euch, wenn ihr mir helfen könnt.
Ich will ein Quiz programmieren. Das besteht aus 3 Formularen: das Hauptmenü, das Quiz an sich und der Frageneditor.
Den Frageneditor hab ich fertig geschrieben mit einem RECORD, damit für jede Frage sämtliche Antworten dabei sind. Diese Fragen kann man abspeichern und wieder öffnen. Bloß, immer wenn ich das öffne, in mein Formular fürs Quiz gehe, zeigt der mir nix aus dem RECORD an.
Ich hab schon mal geguckt und mit Public-Deklaration im type geht nich oder sowas, weils ja ein RECORD ist. Kann mir einer helfen, damit ich das Teil auch in der anderen Unit verwenden kann?
Danke schon mal im voraus.
Hiob
|
|
.Chef
      
Beiträge: 1112
|
Verfasst: Do 02.12.04 09:51
Setze den Record in den type-Bereich im interface einer Unit, die alle verwenden:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10:
| unit Null815;
interface
type Fragen = record Level : Byte; Frage : string; Antwort : string; end; |
Delphi-Quelltext 1: 2: 3: 4: 5:
| unit Eins815;
interface uses Null815; |
Gruß,
Jörg
_________________ Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 02.12.04 10:15
Und in Unit Eins815 greifst du dann auf den Record zu, indem du schreibst:
Delphi-Quelltext 1:
| Null815.Recordvariable |
das ganze heißt dann voll qualifizierter Zugriff.
|
|
Hiob 
Hält's aus hier
Beiträge: 12
|
Verfasst: Do 02.12.04 15:02
und wo muss dieser Recordvariable reingeschrieben werden? in die prozedur?
gruß
hiob
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 02.12.04 15:08
Irgendwo musst du doch schon ein Variable haben. Sonst könntest du die Daten doch nicht speichern.
Vielleicht zeigst du uns mal ein bisschen Source: Wo ist die Variable deklariert? Wo willst du sie benutzen? ...
|
|
Hiob 
Hält's aus hier
Beiträge: 12
|
Verfasst: Do 02.12.04 15:22
das ist die unit, die kein formular besitzt und auf die alle zugreifen...bzw. zugreifen müssten:
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:
| unit Unit1;
interface
type t_frage = record nr: byte; frage: string[200]; antwortr: array[1..4] of string[20]; antwortf: array[1..6] of string[20]; end; t_katalog = array[1..50] of t_frage; t_datei = file of t_frage; t_datname = string;
var v_dat: t_datei; v_datname: t_datname; v_iq: t_katalog; index: byte=1; max: byte=1;
implementation
end.
---------------------- Datei-Ende------------------------------- |
das hier ist der editor, wo der RECORD verändert wird:
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: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186:
| unit QuizEditor;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons, Menus, Unit1;
type
... <==ab hier stehen keine besonderen deklarationen
procedure TForm3.Speichern2Click(Sender: TObject); var i: byte; iq: t_frage; begin if savedialog.execute then begin v_datname:=savedialog.filename; assignfile(v_dat,v_datname); rewrite(v_dat); for i:=1 to max do begin iq:=v_iq[i]; write(v_dat,iq); end; closefile(v_dat); end; end;
procedure TForm3.Speichern1Click(Sender: TObject); var i: byte; iq: t_frage;
begin if opendialog.execute then begin v_datname:=opendialog.filename; assignfile(v_dat,v_datname); reset(v_dat); max:=filesize(v_dat); for i:=1 to max do begin read(v_dat,iq); v_iq[i]:=iq; end; closefile(v_dat); index:=1; iq:=v_iq[index]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end;
end;
procedure TForm3.Button1Click(Sender: TObject); var iq: t_frage; begin index:=1; iq:=v_iq[index]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end;
procedure TForm3.Button2Click(Sender: TObject); var i: byte; iq: t_frage; begin if index>1 then begin i:=index-1; index:=i; iq:=v_iq[i]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end; end;
procedure TForm3.ButtonueberClick(Sender: TObject); var i: byte; iq: t_frage; begin i:=strtoint(Editnr.Text); with iq do begin nr:=strtoint(Editnr.Text); frage:=Editfrage.Text; antwortr[1]:=Editantwortr1.Text; antwortf[1]:=Editantwortf1.Text; antwortf[2]:=Editantwortf2.Text; antwortf[3]:=Editantwortf3.Text; antwortf[4]:=Editantwortf4.Text; antwortf[5]:=Editantwortf5.Text; antwortf[6]:=Editantwortf6.Text; end; v_iq[index]:=iq; if index<50 then index:=index+1; if index>=max then begin editnr.text:=inttostr(index); editfrage.text:=' '; editantwortr1.text:=' '; editantwortf1.text:=' '; editantwortf2.text:=' '; editantwortf3.text:=' '; editantwortf4.text:=' '; editantwortf5.text:=' '; editantwortf6.text:=' '; max:=index; end else begin iq:=v_iq[index]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end; editfrage.SetFocus; end;
procedure TForm3.Button3Click(Sender: TObject); var i: byte; iq: t_frage; begin if index<50 then begin i:=index+1; index:=i; iq:=v_iq[i]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end; end;
procedure TForm3.Button4Click(Sender: TObject); var iq: t_frage; begin index:=max; iq:=v_iq[index]; editnr.text:=inttostr(index); editfrage.text:=iq.frage; editantwortr1.text:=iq.antwortr[1]; editantwortf1.text:=iq.antwortf[1]; editantwortf2.text:=iq.antwortf[2]; editantwortf3.text:=iq.antwortf[3]; editantwortf4.text:=iq.antwortf[4]; editantwortf5.text:=iq.antwortf[5]; editantwortf6.text:=iq.antwortf[6]; end;
end. |
und das ist das quiz...noch nich ganz fertig, aber dort soll dann der RECORD (verändert durch den editor) aufgerufen werden:
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:
| unit QuizFrage;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
type TForm2 = class(TForm) ...
private public end;
var Form2: TForm2; radio: array[1..4] of tradiobutton; implementation uses Unit1; {$R *.dfm} |
joah...das ist fast alles, was ich bisher hab...danke für eure hilfe.
gruß
hiob
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 02.12.04 15:29
In der Unit QuizFrage musst du nur noch die Unit1 in der Uses-Klausel angeben. Dann kannst du dir in der Unit QuizFrage eine Variable vom Typ t_frage definieren. Die musst du dann nicht mal voll qualifiziert schreiben.
|
|
Hiob 
Hält's aus hier
Beiträge: 12
|
Verfasst: Do 02.12.04 15:34
hhm...nur ums nochmal zu betonen: bin amateur
also ich hab in der unit quizfrage "unit1" in die uses des interfaces geschrieben...dafür musste ich "unit1" aus der uses der implementation nehmen...ist das so korrekt? weil...es funktioniert nich
oder...ich hab vielleicht einen fehler bei der ausgabe gemacht. kann mir bitte jemand mal die ausgabe schreiben für einen record? meinetwegen die stelle 1.
danke.
gruß
hiob
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 02.12.04 15:43
| Hiob hat folgendes geschrieben: | hhm...nur ums nochmal zu betonen: bin amateur
also ich hab in der unit quizfrage "unit1" in die uses des interfaces geschrieben...dafür musste ich "unit1" aus der uses der implementation nehmen...ist das so korrekt? weil...es funktioniert nich
gruß
hiob |
Die Unit1 darf nur entweder oder eingebunden sein. Auf jeden Fall bevor die Variable deklariert wird. Sonst kennt der Compiler den Typ nicht.
Beispiel:
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:
| unit QuizFrage;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, Unit1;
type TForm2 = class(TForm) ...
private public end;
var Form2: TForm2; radio: array[1..4] of tradiobutton; Frage: t_frage;
implementation |
So müsstest du die Variable "Frage" in der ganzen Unit "Quizfrage" benutzen können.
|
|
Hiob 
Hält's aus hier
Beiträge: 12
|
Verfasst: Do 02.12.04 15:46
danke...es funktioniert...das mit der ausgabe klappt jetzt auch alles.
nochmals danke für deine hilfe.
gruß
hiob
|
|