Autor Beitrag
DnC
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 98

XP
Delphi 3,6,7,2005 PE
BeitragVerfasst: Mo 30.04.07 13:21 
ich habe einen Typ TDrawCommand, von dem wird ein Typ TDrawLine abgeleitet (und später andere)

Dann habe ich ein Array von Typen TDrawCommand, bei denen ich irgendwann prüfen will

ausblenden Delphi-Quelltext
1:
2:
if (Liste[i] is TDrawLine)
then (Liste[i] as TDrawLine).MachWas;


So wie ich mir das denke, müsste das funktionieren.
Die Definitionen sehen so aus

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type TDrawCommand = class(TObject);

type TDrawLine = class(TDrawCommand)
  XSrc,YSrc,XDest,YDest:Integer;
  Size:Integer;
  Color:TColor;
end;


Mein Problem ist: Da kommt ein Fehler bei  if (Liste[i] is TDrawLine), den ich mir einfach nicht erklären kann. (Access Violation)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 30.04.07 13:23 
Existiert Liste[i] denn überhaupt? Wahrscheinlich nämlich nicht ;-)

_________________
We are, we were and will not be.
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 30.04.07 13:24 
man Gausi...war ich wohl zu langsam :shock:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 for i:= low(Liste) to high(liste) do
 begin
  if (liste[i] = TDrawLine) then
   ...
 end;

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
DnC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 98

XP
Delphi 3,6,7,2005 PE
BeitragVerfasst: Mo 30.04.07 13:27 
ziemlich sicher, denn der Fehler tritt nur auf, wenn was reingeschrieben ist
und einen Fehler gibts beim is - Operator ja auch nur, wenn man Typen vergleicht, die nichts miteinander zu tun haben, was ja nicht der Fall ist... ich verstehs nicht :(

die Version mit = geht nicht, inkompatible Typen


Zuletzt bearbeitet von DnC am Mo 30.04.07 13:31, insgesamt 1-mal bearbeitet
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Mo 30.04.07 13:31 
user profile iconDnC hat folgendes geschrieben:
ziemlich sicher, denn der Fehler tritt nur auf, wenn was reingeschrieben ist

die Version mit = geht nicht, inkompatible Typen


sorry warn fehler meinerseits!

is ist schon richtig..entschuldige!

Hmm..Poste doch mal bissl Code :)

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
DnC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 98

XP
Delphi 3,6,7,2005 PE
BeitragVerfasst: Mo 30.04.07 13:36 
sooo viel gibts da nicht zu posten...

im Prinzip hatte ich mal Lust einen Vektorzeichenprogramm zu basteln...

ausblenden 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:
function TVektorhandler.Draw(var Res:TBitmap; var Log:TStringlist):Boolean;//Gibt das Ergebnis bzw. ob es Fehler gab
var a:Integer;
    Cmd:TDrawCommand;
    tmpLog:TStringList;
begin

 tmpLog:=TStringlist.Create;
 tmpLog.Add('Log of Drawing............................');
 tmpLog.Add('');

  for a:=0 to High(self.Commands) do
  begin
    Cmd:=self.Commands[a];

    if (Cmd is TDrawLine)
    then
     begin
       Res.Canvas.Pen.Width:=(Cmd as TDrawLine).Size;
       Res.Canvas.Pen.Color:=(Cmd as TDrawLine).Color;
       Res.Canvas.MoveTo((Cmd as TDrawLine).XSrc,(Cmd as TDrawLine).YSrc);
       Res.Canvas.MoveTo((Cmd as TDrawLine).XDest,(Cmd as TDrawLine).YDest);
       tmpLog.Add('Line Drawn: ['+inttostr((Cmd as TDrawLine).XSrc) + ';' + inttostr((Cmd as TDrawLine).YSrc) + '] --> [' + inttostr((Cmd as TDrawLine).XDest) + ';' + inttostr((Cmd as TDrawLine).YDest) + ']');
     end;
  end;
 Log:=tmpLog;
 result:=true;
end;


die Malanweisungen sind in einem dynamischen Array

ausblenden Delphi-Quelltext
1:
Commands: array of TDrawCommand;					


die Definitionen sind wie gesagt

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
type TDrawCommand = class(TObject);

type TDrawLine = class(TDrawCommand)
  XSrc,YSrc,XDest,YDest:Integer;
  Size:Integer;
  Color:TColor;
end;


Eingefügt wird in das dynamische Array mit

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var evt:TDrawLine;
begin
if ssLeft in Shift then
begin
 evt:=TDrawLine.Create;
 evt.XSrc:=lastX;
 evt.XDest:=X;
 evt.YSrc:=lastY;
 evt.YDest:=Y;
 evt.Color:=Image1.Canvas.Pen.Color;
 evt.Size:=Image1.Canvas.Pen.Width;
 DrawHandler.AddCommand(TDrawCommand(evt));
 Image1.Canvas.MoveTo(lastX,lastY);
 Image1.Canvas.LineTo(X,Y);
 lastX:=X;
 lastY:=Y;
 evt.Free;
end;
end;


Der Fehler tritt auf, wenn ich das Bild aus den gespeicherten Daten "nachmalen" lassen will, also jede halbe Sekunde in nem Timer:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Timer1Timer(Sender: TObject);
var tmp:TBitmap;
    Log:TStringList;
begin
 tmp:=TBitmap.Create;
 tmp.Width:=Image1.Width;
 tmp.Height:=Image1.Height;
 StatusBar.Panels[1].Text:='Aktualisiere Bild';
 DrawHandler.Draw(tmp,Log);
 Image1.Canvas.Draw(0,0,tmp);
 StatusBar.Panels[1].Text:='';
end;


Das ist so der Code, den es dazu gibt...

thx. auch für Hinweise, die den sonstigen Code betreffen^^
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4708
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Mo 30.04.07 14:58 
In Image1MouseMove zerstörst du das DrawLine Object (evt.Free) wieder.

Dein DrawHandler möchte dieses Objekt aber später im TimerEvent verwenden obwohl es schon zerstört ist.
Der IS Operator ist nur zufällig der erste Zugriff auf dieses (Ex)Objekt.

Gruß
DnC Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 98

XP
Delphi 3,6,7,2005 PE
BeitragVerfasst: Mo 30.04.07 16:16 
Genial! Das ist es! warum ich da nicht selbst drauf gekommen bin... :roll: so ein Problem hatte ich auch vorher schon mal... :?