Autor Beitrag
jjturbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Di 23.05.06 10:45 
Moin Forum,

ich möchte gerne ein BitMap über eine Socketverbindung senden.
Mein Testprogramm sieht folgendermassen aus:


Variablendeklaration
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
type TMyRec=Record
      Name       :String[55];
      Vorname    :String[55];
      HausNr     :Integer;
      Male       :Boolean;
      TelefonNr  :Integer;
      Ort        :String[55];
      From       :String[50];
      FromAdress :String[15];
      Gesendet   :TDateTime;
      Empfangen  :TDateTime;
      myBitMap   :TBitMap;
     end;

var MyRec : TMyRec;




Sendender PC
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  with MyRec do begin
    Name         := 'Müller';
    Vorname      := 'Elfriede';
    HausNr       := 13;
    Male         := false;
    TelefonNr    := 999888555;
    Ort          := 'Irgendwo';
    Gesendet     := Now;
    Empfangen    := StrToTime('00:00:00');
    myBitMap     := Image1.Picture.Bitmap;//Dort ist irgendein Bild geladen
  end;

  for i := 0 to ServerSocket1.Socket.ActiveConnections-1
   do ServerSocket1.Socket.Connections[i].SendBuf(MyRec,SizeOf(MyRec));



Empfangender PC
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
  Socket.ReceiveBuf(MyRec,SizeOf(MyRec));
  Image1.Picture.Bitmap := MyRec.myBitMap;//Zugriffsverletzung

end;


Die Daten werden empfangen, können auch alle richtig ausgewertet werden, nur das BitMap läßt sich nicht verwenden, sobald ich versuche dieses in mein Image zu laden, bekomme ich eine Zugriffsverletzung?
Weiß jemand Rat?

Dank Euch,

Gruß jjturbo

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 23.05.06 10:57 
Moin!

Du kannst keine dynamischen Objekte in einem Record versenden, die Variable vom Typ TBitmap ist doch nur ein Zeiger auf Daten, die auf dem Heap liegen... :roll: ist immer das gleiche mit dem Senden von Records... ;)

Du musst die Bilddaten selbst senden, da kommst du mit .Scanlines[] des Bitmap-Objekts ran. Um mit der Datenübertragung keine Probleme zu bekommen (ich kann nur dringend davon abraten, records zu versenden!), brauchst du ein Suche in: Delphi-Forum, Delphi-Library PROTOKOLL, und hier kannst du mehr darüber erfahren. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jjturbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Di 23.05.06 11:01 
Ok, das mit dem BitMap leuchtet mir ein... :oops:

Aber wieso keine Records versenden?

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
rd3
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 23.05.06 11:02 
Moin,

hier ist ein Beispiel, wie man BMPs übers Netzwerk verschickt:
delphi.about.com/od/...anet/l/aa012004a.htm

Gruß rd3
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Di 23.05.06 11:25 
Moin!

user profile iconjjturbo hat folgendes geschrieben:
Aber wieso keine Records versenden?

Die ausführliche Erklärung findest du zum einen im Tut, zum anderen hast du den Hauptgrund doch schon selbst "entdeckt": dynamische Objekte (lange Strings, etc.). ;)

Weiterhin, dein Code ist potentiell defekt:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
begin
  Socket.ReceiveBuf(MyRec,SizeOf(MyRec));
  Image1.Picture.Bitmap := MyRec.myBitMap;//Zugriffsverletzung (klar, darum geht´s jetzt aber nicht)
end;

Was ist denn, wenn nicht das ganze Record eingetroffen ist? Du wertest nämlich nicht das Funktionsergebnis von ReceiveBuf aus, was die tatsächlich gelesene Anzahl Bytes liefert - und wer sagt, dass das SizeOf(MyRec) ist? :shock:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jjturbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Di 23.05.06 11:31 
Ok ok, werde mir jetzt mal das Tut reinziehen :)


Vielen Dank erst mal für Eure Antworten.

Gruß, jjturbo

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 31.05.06 01:23 
Moin!

Ich habe mal die ganze Problematik zu einem FAQ-Eintrag eingedampft. ;) Kommt doch einfach immer noch zu oft vor, diese Frage...

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jjturbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Mi 31.05.06 06:24 
Ich habe mir mittlerweile mal das Tutorial einverleibt, ich kann nur jedem, der noch nichts mit diesem Thema zu tun hatte, dringend empfehlen das mal durchzuarbeiten, lohnt sich wirklich!!!

Danke an Narses für dieses tolle Tutorial!!!

Gruß, jjturbo

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 29.06.06 10:08 
Moin!

Im Terminatorzeichen-Protokoll-Tutorial Teil 2 wird eine Möglichkeit vorgestellt, wie man ein Bild (TBitmap) übertragen kann - also genau das, was hier die Problemstellung ist. ;)

Ich möchte aber noch darauf hinweisen, dass es sich um eine Übergangslösung handelt. Die "größe Lösung", das Binär-Protokoll-Tutorial, dauert leider noch ein bischen (ist wirklich viel Stoff... :?).

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 13.10.06 15:17 
Moin!

Hinweis: Mein voriger Beitrag bezog sich auf eine ältere Version des Tutorials. Das Tutorial liegt mittlerweile in einer neuen, deutlich verbesserten Version vor, so dass jemand, der auf der alten Version aufgesetzt hatte, eventuell einen Blick auf die neue Version werfen möchte. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.