Autor Beitrag
ardani
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36

Win XP
Delphi 6, C++ (VS Express)
BeitragVerfasst: Fr 12.02.10 12:30 
Habe mir jetzt folgenden Code "gebastelt", bekomme aber 2 Fehlermeldungen, mit denen ich leider nicht viel anfangen kann...

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:
unit Unit2;

interface

uses
  Winsock, Windows, Messages, SysUtils, Variants, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ScktComp, Classes;

type
  THostName = class(TThread)
  private
    { Private declarations }
    Faus, FIP: string;
    FJ:byte;
    FBox : TStringgrid;
    procedure DoUpdateVLC;
  public
    { Public declarations }
    constructor Create(comp:TStringGrid; j:byte; IP:string);
  protected
    procedure Execute; override;
    procedure UpdateVLC(aus:string);
  end;


implementation

{ Important: Methods and properties of objects in VCL or CLX can only be used
  in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure THostName.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }


{ THostName }

constructor THostName.Create(comp:TStringGrid; j:byte; IP:string);
begin
  Fj := j;
  FIP := IP;
  FBox := comp;
  FreeOnTerminate := True;
  inherited Create(False);
end;

procedure THostName.DoUpdateVLC;
begin
FBox.cells[3,Fj] := Faus;
end;

procedure THostName.UpdateVLC(aus:string);
begin
Faus := aus;
synchronize(DoUpdateVLC);
end;


procedure THostName.Execute;
var
    aus: string;
    IPv4: in_addr;
    HostEnt: PHostEnt;
begin
  IPv4.S_addr := inet_addr(PAnsiChar(FIP));
  HostEnt := gethostbyaddr(@IPv4, SizeOf(IPv4), AF_INET);
  if Assigned(HostEnt) then
   aus := StrPas(Hostent^.h_name)
  else
   aus := '';
  UpdateVLC(aus);
end;

initialization
  WSAStartup($101, WSAData); //  <<- erste Fehlermeldung

finalization  //  <<- zweite Fehlermeldung
  WSACleanup;

end.


[Error] Unit2.pas(79): '(' expected but ')' found
[Error] Unit2.pas(81): Constant object cannot be passed as var parameter

leider komme ich an dem Punkt nicht weiter, nehme ich die Zeilen raus, funktioniert das Script zwar, macht aber logischerweise nicht das was ich will.

vielen Dank schonmal für die Hilfe
Astat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 75
Erhaltene Danke: 1

Windows 2000
D6, D7, D2007, Lazarus
BeitragVerfasst: Fr 12.02.10 13:05 
Hallo ardani,

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:
unit uHostNameThread;

interface

uses
  Windows, Classes, Sysutils, Messages;

type
  THostNameThread = class(TThread)
  private
    FHostName, FIP: string;
  public
    constructor Create(IP: string; CBOnTerminateProc: TNotifyEvent);
    property HostName: string Read FHostName;
  protected
    procedure Execute; override;
  end;


implementation

uses
  Winsock;

{ THostNameThread }

constructor THostNameThread.Create(IP:string; CBOnTerminateProc: TNotifyEvent);
begin
  inherited Create(true);
  FreeOnTerminate := True;
  OnTerminate := CBOnTerminateProc;
  Resume;
end;

procedure THostNameThread.Execute;
var
  SockAddrIn: TSockAddrIn;
  HostEnt: PHostEnt;
begin
  SockAddrIn.sin_addr.s_addr := inet_addr(PAnsiChar(FIP));
  HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
  if HostEnt <> nil then
   FHostName := StrPas(Hostent^.h_name)
  else
   FHostName := '';
end;

var
  WSAData: TWSAData;

initialization
  WSAStartup($101, WSAData);

finalization
  WSACleanup;
  
end.

//-- Code in der Mainform

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    procedure OnTerminateProc(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.OnTerminateProc(Sender: TObject);
begin
  ShowMessage(THostNameThread(Sender).HostName);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  THostNameThread.Create('127.0.0.1', OnTerminateProc);
end;


lg. Astat
ardani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36

Win XP
Delphi 6, C++ (VS Express)
BeitragVerfasst: Fr 12.02.10 15:45 
vielen Dank Astat, so hat es jetzt Funktioniert, kann mir vllt trotzdem noch jemand erklären, was an meinem falsch war ? nur zum Verständnis.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 12.02.10 16:41 
user profile iconardani hat folgendes geschrieben Zum zitierten Posting springen:
vielen Dank Astat, so hat es jetzt Funktioniert, kann mir vllt trotzdem noch jemand erklären, was an meinem falsch war ? nur zum Verständnis.

Guck mal ganz scharf hin, wo der Unterschied ist ;)

ausblenden Delphi-Quelltext
1:
2:
var
  WSAData: TWSAData;

Das war nicht deklariert.

Und offenbar ist WSAData auch der Name eines Typs oder einer Funktion, so dass der Compiler diese angenommen hat. Aber leider völlig unpassend, deswegen die Fehler.
Ein anderer Name hätte dann wohl auch den richtigen Fehler geworfen, "undefinierter Bezeichner".

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
ardani Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 36

Win XP
Delphi 6, C++ (VS Express)
BeitragVerfasst: Fr 12.02.10 17:20 
Nachdem Astat seins hier gepostet hatte, habe ich es gesehen und hatte es in meins eingebaut, weil ich Wissen wollte, ob das dann geht, aber merkwürdiger weise kam wieder der gleiche Fehler, deswegen hatte es mich ja gewundert.

Trotzdem vielen Dank für die Hilfe und die antworten
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 12.02.10 17:36 
Hm, user profile iconAstat hat auch die uses etwas aufgeräumt.
Kann gut sein dass die Kollision in einer von denen war. ScktComp klingt schonmal verdächtig.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."