Autor Beitrag
volvox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 13:14 
Hallo,
ich schreibe bald ne Info Kursarbeit und hab das Thema "Eigene Prozeduen erstellen" größtenteils verpasst.
Kann mir bitte irgendjemand nochmal kurz erklären wie man die deklariert und anwendet, oder ein gaaanz einfaches Programm schicken, damit ich mir einfach den Aufbau mal angucken kann?

z.B. so was wie einfach einen Punkt auf die Canvas zeichnen mit der Prozedur: ZeichnePunkt(x,y:integer);

Bitte mit kompletten Quelltext oder ganzem Programm, damit ich verstehe was wo hinkommt.

Wär echt super, wenn mir jemand helfen würde.

Danke!


Moderiert von user profile iconChristian S.: Topic aus Sonstiges (Delphi) verschoben am Sa 16.12.2006 um 14:30
Moderiert von user profile iconChristian S.: Titel geändert
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Sa 16.12.06 13:21 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure DrawPoint(var aCanvas: TCanvas; aPoint: TPoint; aColor: TColor);
begin
  aCanvas.Pixels[aPoint.x, aPoint.y] := aColor;
end;


so zB das schreibst du unter implementation

hier kannst du alles wichtige nachlesen: www.christian-stelzm...rtikel/crashkurs.htm

mfg
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 13:34 
danke, aber mit "aPoint" oder "aCanvas" kann ich nix anfangen. außerdem fhelt da ja noch der obere teil. unter "type" müsste doch normal so was stehen wie

procedure zeichnen(a,b:integer); oder

ich dachte das eigentlich ungefähr so:

oben

ausblenden Delphi-Quelltext
1:
procedure zeichnen(a,b:integer);					


dann wird die prozedur irgendwo ausgelöst also z.B.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1(Sender: TObject);
begin                                     
  zeichnen                                
end;


und dann halt irgendwo noch der eigenliche inhalt der Prozedur wie

ausblenden Delphi-Quelltext
1:
image1.canvas.pixels[x,y]:=clRed;					


wie lässt sich das denn realisieren?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Sa 16.12.06 13:42 
Hi!

aPoint sind die Koordinaten als TPoint, aCanvas ist das Canvas-Objekt von z.B. deiner Form und AColor ist die Farbe als TColor. Ein Aufruf könnte zum Beispiel so aussehen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure DrawPoint(var aCanvas: TCanvas; aPoint: TPoint; aColor: TColor);  
begin  
  aCanvas.Pixels[aPoint.x, aPoint.y] := aColor;  
end; 

procedure TForm1.Button1Click(Sender: TObject);
begin
  DrawPoint(Canvas, Point(50, 50), clBlue);
end;
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 13:46 
super, vielen danke, aber ich brauchs echt in der anderen form, weil ich das in der arbeit nicht völlig anders bringen kann als wir es gelern haben
Xion
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
EE-Maler
Beiträge: 1952
Erhaltene Danke: 128

Windows XP
Delphi (2005, SmartInspect), SQL, Lua, Java (Eclipse), C++ (Visual Studio 2010, Qt Creator), Python (Blender), Prolog (SWIProlog), Haskell (ghci)
BeitragVerfasst: Sa 16.12.06 14:17 
user profile iconvolvox hat folgendes geschrieben:

oben

***procedure zeichnen(a,b:integer);***


wäre dann beim type TForm1 unter public:

ausblenden Delphi-Quelltext
1:
2:
   public
     procedure Zeichnen;


user profile iconvolvox hat folgendes geschrieben:

dann wird die prozedur irgendwo ausgelöst also z.B.

***procedure TForm1.Button1(Sender: TObject);***
***begin ***
*** zeichnen ***
***end; ***


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1(Sender: TObject);
begin                                    
  Zeichnen;                               
end;


user profile iconvolvox hat folgendes geschrieben:

und dann halt irgendwo noch der eigenliche inhalt der Prozedur wie

***image1.canvas.pixels[x,y]:=clRed; ***


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Zeichnen;
begin
  image1.canvas.pixels[x,y]:=clRed;
end;


normalerweise nimmt man dann die Koordinaten x,y als parameter mit, aber wenn du Chryzlers Lösung nicht willst, dann halt so ;)

_________________
a broken heart is like a broken window - it'll never heal
In einem gut regierten Land ist Armut eine Schande, in einem schlecht regierten Reichtum. (Konfuzius)
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 14:24 
danke, das sieht sehr gut aus. kann ich bestimmt gebrauchen
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 17:02 
noch was: wenn ich die variablen jetzt hinter dem namen der prozedur angeben will, also zeichne(x,y:integer) , wo schreib ich das hin und wie sind die variablen deklariert?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Sa 16.12.06 17:33 
Diese Variablen nennt man wie bei einer mathematischen Funktion Parameter. Das solltest du wohl auch für die Arbeit wissen ;-).

Und die schreibst du einfach so wie du es getan hast in Klammern hinter den Funktionsnamen, sowohl oben in der Deklaration in deiner Formulardeklaration unter type als auch unten in der Implementierung der Klasse (und damit der Funktion).

Die hervorgehobenen Begriffe solltest du dir eventuell ansehen... Wenn du weißt, was das ist, und du die in der Arbeit korrekt anwendest (wenn ihr die nicht sowieso wissen sollt ;-)), ist das bestimmt nicht schlecht ;-).

Aber warum probierst du das eigentlich nicht einfach aus??? Ich meine, du musst doch nur ein neues Projekt machen, in dem du dir beispielsweise mit ShowMessage(IntToStr(a)); in einer selbstdeklarierten Funktion bzw. Prozedur den Parameter a vom Typ Integer ausgeben lässt.
Abgesehen davon: Es wurde schon der Crashkurs von Christian erwähnt. Da kannst du das alles leicht verständlich nachlesen!
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Sa 16.12.06 17:42 
ok. das hilft danke.

und nein, wir haben begriffe wie parameter, praktisch nicht verwendet.