Autor Beitrag
kai4711
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Do 19.05.05 17:13 
Hallo zusammen,

ich habe ein dickes Anfängerproblem.
Und zwar möchte ich innerhalb einer eingenen Prozedur auf den Text eines Textfeldes zugreifen per zB textsongminute.text='';.
In meiner Prozedur sagt er mir aber, dass er textsongminute gar nicht kennen würden.

In anderen Prozeduren zB der Automatisch erstellten für nen Klick auf das Feld funktioniert selbiges.
Hier mal mein schöner .NET 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:
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:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
unit backtimer;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data,  Borland.Vcl.SysUtils;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    /// <summary>
    /// Required designer variable.
    /// </summary>
    Components: System.ComponentModel.Container;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    Label4: System.Windows.Forms.Label;
    Label5: System.Windows.Forms.Label;
    Panel1: System.Windows.Forms.Panel;
    Panel2: System.Windows.Forms.Panel;
    Textbeginhour: System.Windows.Forms.TextBox;
    Textbeginminute: System.Windows.Forms.TextBox;
    Textbeginsecond: System.Windows.Forms.TextBox;
    Textsongminute: System.Windows.Forms.TextBox;
    Textsongsecond: System.Windows.Forms.TextBox;
    Textadsecond: System.Windows.Forms.TextBox;
    Textadminute: System.Windows.Forms.TextBox;
    Label6: System.Windows.Forms.Label;
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    procedure InitializeComponent;
  {$ENDREGION}
  strict protected
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$AUTOBOX ON}

{$REGION 'Windows Form Designer generated code'}
/// <summary>
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
/// </summary>
procedure TWinForm.InitializeComponent;
begin
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.Label4 := System.Windows.Forms.Label.Create;
  Self.Label5 := System.Windows.Forms.Label.Create;
  Self.Panel1 := System.Windows.Forms.Panel.Create;
  Self.Textadminute := System.Windows.Forms.TextBox.Create;
  Self.Textadsecond := System.Windows.Forms.TextBox.Create;
  Self.Textsongsecond := System.Windows.Forms.TextBox.Create;
  Self.Textsongminute := System.Windows.Forms.TextBox.Create;
  Self.Textbeginsecond := System.Windows.Forms.TextBox.Create;
  Self.Textbeginminute := System.Windows.Forms.TextBox.Create;
  Self.Textbeginhour := System.Windows.Forms.TextBox.Create;
  Self.Panel2 := System.Windows.Forms.Panel.Create;
  Self.Label6 := System.Windows.Forms.Label.Create;
  Self.Panel1.SuspendLayout;
  Self.Panel2.SuspendLayout;
  Self.SuspendLayout;
  // 
  // Label1
  // 
  Self.Label1.BackColor := System.Drawing.Color.FromArgb((Byte(0)), (Byte(192)), 
      (Byte(0)));
  Self.Label1.Font := System.Drawing.Font.Create('Microsoft Sans Serif'9.75
      System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte(0)));
  Self.Label1.Location := System.Drawing.Point.Create(816);
  Self.Label1.Name := 'Label1';
  Self.Label1.Size := System.Drawing.Size.Create(11216);
  Self.Label1.TabIndex := 0;
  Self.Label1.Text := 'News-Beginn:';
  // 
  // Label2
  // 
  Self.Label2.BackColor := System.Drawing.Color.FromArgb((Byte(0)), (Byte(192)), 
      (Byte(0)));
  Self.Label2.Font := System.Drawing.Font.Create('Microsoft Sans Serif'9.75
      System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte(0)));
  Self.Label2.Location := System.Drawing.Point.Create(880);
  Self.Label2.Name := 'Label2';
  Self.Label2.Size := System.Drawing.Size.Create(11216);
  Self.Label2.TabIndex := 1;
  Self.Label2.Text := 'Dauer Werbung:';
  // 
  // Label3
  // 
  Self.Label3.BackColor := System.Drawing.Color.FromArgb((Byte(0)), (Byte(192)), 
      (Byte(0)));
  Self.Label3.Font := System.Drawing.Font.Create('Microsoft Sans Serif'9.75
      System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte(0)));
  Self.Label3.Location := System.Drawing.Point.Create(848);
  Self.Label3.Name := 'Label3';
  Self.Label3.Size := System.Drawing.Size.Create(9616);
  Self.Label3.TabIndex := 2;
  Self.Label3.Text := 'Letzter Titel:';
  // 
  // Label4
  // 
  Self.Label4.BackColor := System.Drawing.Color.Red;
  Self.Label4.Font := System.Drawing.Font.Create('Microsoft Sans Serif'9.75
      System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte(0)));
  Self.Label4.Location := System.Drawing.Point.Create(8128);
  Self.Label4.Name := 'Label4';
  Self.Label4.Size := System.Drawing.Size.Create(11223);
  Self.Label4.TabIndex := 3;
  Self.Label4.Text := 'Start letzter Titel:';
  // 
  // Label5
  // 
  Self.Label5.BackColor := System.Drawing.Color.Red;
  Self.Label5.Font := System.Drawing.Font.Create('Microsoft Sans Serif'9.75
      System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte(0)));
  Self.Label5.Location := System.Drawing.Point.Create(8160);
  Self.Label5.Name := 'Label5';
  Self.Label5.TabIndex := 4;
  Self.Label5.Text := 'Start Werbung:';
  // 
  // Panel1
  // 
  Self.Panel1.BackColor := System.Drawing.Color.FromArgb((Byte(0)), (Byte(192)), 
      (Byte(0)));
  Self.Panel1.Controls.Add(Self.Textadminute);
  Self.Panel1.Controls.Add(Self.Textadsecond);
  Self.Panel1.Controls.Add(Self.Textsongsecond);
  Self.Panel1.Controls.Add(Self.Textsongminute);
  Self.Panel1.Controls.Add(Self.Textbeginsecond);
  Self.Panel1.Controls.Add(Self.Textbeginminute);
  Self.Panel1.Controls.Add(Self.Textbeginhour);
  Self.Panel1.Location := System.Drawing.Point.Create(00);
  Self.Panel1.Name := 'Panel1';
  Self.Panel1.Size := System.Drawing.Size.Create(328112);
  Self.Panel1.TabIndex := 5;
  // 
  // Textadminute
  // 
  Self.Textadminute.BackColor := System.Drawing.Color.FromArgb((Byte(224)), (Byte(224)), 
      (Byte(224)));
  Self.Textadminute.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textadminute.Font := System.Drawing.Font.Create('Microsoft Sans Serif'
      9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textadminute.Location := System.Drawing.Point.Create(19280);
  Self.Textadminute.MaxLength := 2;
  Self.Textadminute.Name := 'Textadminute';
  Self.Textadminute.Size := System.Drawing.Size.Create(2422);
  Self.Textadminute.TabIndex := 5;
  Self.Textadminute.Text := '00';
  // 
  // Textadsecond
  // 
  Self.Textadsecond.BackColor := System.Drawing.Color.FromArgb((Byte(224)), (Byte(224)), 
      (Byte(224)));
  Self.Textadsecond.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textadsecond.Font := System.Drawing.Font.Create('Microsoft Sans Serif'
      9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textadsecond.Location := System.Drawing.Point.Create(23280);
  Self.Textadsecond.MaxLength := 2;
  Self.Textadsecond.Name := 'Textadsecond';
  Self.Textadsecond.Size := System.Drawing.Size.Create(2422);
  Self.Textadsecond.TabIndex := 6;
  Self.Textadsecond.Text := '00';
  // 
  // Textsongsecond
  // 
  Self.Textsongsecond.BackColor := System.Drawing.Color.FromArgb((Byte(224)), 
      (Byte(224)), (Byte(224)));
  Self.Textsongsecond.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textsongsecond.Font := System.Drawing.Font.Create('Microsoft Sans Ser' +
    'if'9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textsongsecond.Location := System.Drawing.Point.Create(23248);
  Self.Textsongsecond.MaxLength := 2;
  Self.Textsongsecond.Name := 'Textsongsecond';
  Self.Textsongsecond.Size := System.Drawing.Size.Create(2422);
  Self.Textsongsecond.TabIndex := 4;
  Self.Textsongsecond.Text := '00';
  // 
  // Textsongminute
  // 
  Self.Textsongminute.BackColor := System.Drawing.Color.FromArgb((Byte(224)), 
      (Byte(224)), (Byte(224)));
  Self.Textsongminute.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textsongminute.Font := System.Drawing.Font.Create('Microsoft Sans Ser' +
    'if'9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textsongminute.Location := System.Drawing.Point.Create(19248);
  Self.Textsongminute.MaxLength := 2;
  Self.Textsongminute.Name := 'Textsongminute';
  Self.Textsongminute.Size := System.Drawing.Size.Create(2422);
  Self.Textsongminute.TabIndex := 3;
  Self.Textsongminute.Text := '00';
  // 
  // Textbeginsecond
  // 
  Self.Textbeginsecond.BackColor := System.Drawing.Color.FromArgb((Byte(224)), 
      (Byte(224)), (Byte(224)));
  Self.Textbeginsecond.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textbeginsecond.Font := System.Drawing.Font.Create('Microsoft Sans Se' +
    'rif'9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textbeginsecond.Location := System.Drawing.Point.Create(23216);
  Self.Textbeginsecond.MaxLength := 2;
  Self.Textbeginsecond.Name := 'Textbeginsecond';
  Self.Textbeginsecond.Size := System.Drawing.Size.Create(2422);
  Self.Textbeginsecond.TabIndex := 2;
  Self.Textbeginsecond.Text := '00';
  // 
  // Textbeginminute
  // 
  Self.Textbeginminute.BackColor := System.Drawing.Color.FromArgb((Byte(224)), 
      (Byte(224)), (Byte(224)));
  Self.Textbeginminute.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textbeginminute.Font := System.Drawing.Font.Create('Microsoft Sans Se' +
    'rif'9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textbeginminute.Location := System.Drawing.Point.Create(19216);
  Self.Textbeginminute.MaxLength := 2;
  Self.Textbeginminute.Name := 'Textbeginminute';
  Self.Textbeginminute.Size := System.Drawing.Size.Create(2422);
  Self.Textbeginminute.TabIndex := 1;
  Self.Textbeginminute.Text := '00';
  // 
  // Textbeginhour
  // 
  Self.Textbeginhour.BackColor := System.Drawing.Color.FromArgb((Byte(224)), 
      (Byte(224)), (Byte(224)));
  Self.Textbeginhour.BorderStyle := System.Windows.Forms.BorderStyle.FixedSingle;
  Self.Textbeginhour.Font := System.Drawing.Font.Create('Microsoft Sans Seri' +
    'f'9.75, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 
      (Byte(0)));
  Self.Textbeginhour.Location := System.Drawing.Point.Create(15216);
  Self.Textbeginhour.MaxLength := 2;
  Self.Textbeginhour.Name := 'Textbeginhour';
  Self.Textbeginhour.Size := System.Drawing.Size.Create(2422);
  Self.Textbeginhour.TabIndex := 0;
  Self.Textbeginhour.Text := '00';
  // 
  // Panel2
  // 
  Self.Panel2.BackColor := System.Drawing.Color.Red;
  Self.Panel2.Controls.Add(Self.Label6);
  Self.Panel2.Location := System.Drawing.Point.Create(0112);
  Self.Panel2.Name := 'Panel2';
  Self.Panel2.Size := System.Drawing.Size.Create(32888);
  Self.Panel2.TabIndex := 6;
  // 
  // Label6
  // 
  Self.Label6.Location := System.Drawing.Point.Create(15216);
  Self.Label6.Name := 'Label6';
  Self.Label6.Size := System.Drawing.Size.Create(10424);
  Self.Label6.TabIndex := 0;
  Self.Label6.Text := 'Label6';
  // 
  // TWinForm
  // 
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(513);
  Self.ClientSize := System.Drawing.Size.Create(274197);
  Self.Controls.Add(Self.Label5);
  Self.Controls.Add(Self.Label4);
  Self.Controls.Add(Self.Label3);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Label1);
  Self.Controls.Add(Self.Panel1);
  Self.Controls.Add(Self.Panel2);
  Self.FormBorderStyle := System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  Self.Name := 'TWinForm';
  Self.Text := 'Backtimer V0.01';
  Self.Panel1.ResumeLayout(False);
  Self.Panel2.ResumeLayout(False);
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;



constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

function AlltoSeconds(hour,minute,second:Int64):Int64;
begin
  AlltoSeconds:=hour*60*60+minute*60+second;
end;

procedure CalcValues(beginhour,beginminute,beginsecond,songminute,songsecond,adminute,adsecond:Int64);
var songstart, adstart:Int64;
begin
  songstart:=AlltoSeconds(beginhour,beginminute,beginsecond)-AlltoSeconds(0,songminute,songsecond);
  textsongminute.text='';
end;
end.


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Do 19.05.05 19:47 
Hallo,

Fehler erkannt: Du hast deine Prozedur nicht der Klasse TWinForm zugeordnet.

Das funktioniert nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure CalcValues(beginhour,beginminute,beginsecond,songminute,songsecond,adminute,adsecond:Int64);  
var songstart, adstart:Int64;  
begin  
  songstart:=AlltoSeconds(beginhour,beginminute,beginsecond)-AlltoSeconds(0,songminute,songsecond);  
  textsongminute.text='';  
end;


Das wird funktionieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TWinForm.CalcValues(beginhour,beginminute,beginsecond,songminute,songsecond,adminute,adsecond:Int64);  
var songstart, adstart:Int64;  
begin  
  songstart:=AlltoSeconds(beginhour,beginminute,beginsecond)-AlltoSeconds(0,songminute,songsecond);  
  textsongminute.text='';  
end;


Siehst du den Unterschied in der ersten Zeile?

Da steht TWinForm.CalcValues

Diesen Fehler mache ich auch öfters, wenn ich zu schusselig bin, den Klassennamen voranzustellen.

Gruß, Feivel
kai4711 Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Do 19.05.05 23:52 
"TWinForm does not contain a member named CalcValues" sagt er mir jetzt?!

Danke schonmal.
feivel3333
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 190

W7
Delphi XE prof
BeitragVerfasst: Fr 20.05.05 13:12 
Das ist mir klar, dass er es sagt.

Dort, wo

procedure InitializeComponent;
procedure CalcValues( beginhour,beginminute,beginsecond,songminute,songsecond,adminute,
adsecond:Int64);


steht, muss auch die Deklaration deiner selbstgeschriebenen Prozedur stehen, und zwar mit allen Parametern.


Er wird dir auch noch weitere Dinge um die Ohren werfen, wenn du dich nicht an die Konventionen von Objekten hältst.

Wenn du in "in der Luft hängenden" Prozeduren und Funktionen, die du nicht durch vorangestellte Klassennamen in deinen Quellcode schreibst, dich auf Objekte bzw. deren Funktionen und Prozeduren beziehst, dann kennt der Compiler diese nicht.

Du solltest dir ein Grundlagenkapitel über Objekte und Klassen reinziehen, um zu verstehen, wie man Prozeduren und Funktionen für Objekte schreibt.

Prinzipiell gibt es einen Deklarationsteil und eine Implementation. Die Deklaration ist oben im Kopf in der Klassenbeschreibung, in diesem Falle z.B. einfach nur die Aufführung von z.B. InitializeComponent.

Weiter unten im Quellcode findest du

IMPLEMENTATION

...
...

procedure TWinForm.InitializeComponent;
begin
...
end;

Das ist die Implementation deiner oben deklarierten procedure.
Verstehst du nun das Vorgehen?

Schreibst du unten nur eine Procedure "in die Luft", dann weiß die Klasse nichts von deren Vorhandensein, die procedure gehört nicht in die Klasse TWinForm.

Deklarierst du sie aber oben und implementierst sie unten mit vorangestelltem TWinForm., dann funktioniert´s.

Gruß, Feivel
kai4711 Threadstarter
Hält's aus hier
Beiträge: 9



BeitragVerfasst: Fr 20.05.05 14:21 
Wunderbar, das war der entscheidende Punkt.

Danke allen beteiligten!