Solved

Testing my component dynamicly with a connection

Posted on 2006-06-16
8
264 Views
Last Modified: 2010-04-05
Dear Experts,

I want to test my component dynamicly with a connection:

but I get the error:
 "[Error] Main.pas(960): '.' expected but ')' found"

at line:  
RecvThrd.Create(soc, DSP32701); (in procedure MakeConnect)

This is the code:

unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, DSP3270, Winsock, utilu, Menus;

type
  RecvThrd = class(TThread)
  private
    IOSocket: TSocket ;
    DataStreamBuf: string ;
    EorFlag: boolean ;
    DSP3270: TDSP3270;

    { Private declarations }
  protected
    procedure ProcessDataStream ;
    procedure Execute; override;
    procedure DumpChar(ch: char) ;
    procedure DumpFlush ;
  public
    constructor Create(ios: TSocket; dsp: TDSP3270) ;
  end;

  TBuf = array[0..IO_BUF_SIZE] of char ;
  TModel = (ibm3278_2, ibm3278_3, ibm3278_4) ;
  TPath = array [0..MAX_PATH] of char ;

  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Connect1: TMenuItem;
    Debugging1: TMenuItem;
    Disconnect1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure DSP32701SendData(Sender: TObject; Data: String);
    procedure Connect1Click(Sender: TObject);
    procedure Debugging1Click(Sender: TObject);
    procedure Disconnect1Click(Sender: TObject);

  private
    { Private declarations }
    ConnectHostName: string ;
    soc: TSocket ;
    socOpen: boolean;
    EorFlag: boolean ;
    DumpStr: string[16] ;
    DumpNum: integer ;
    DumpBytes: integer ;
    RecThread: RecvThrd ;
   
  public
    { Public declarations }
    procedure DumpChar(ch: char) ;
    procedure DumpFlush ;
    procedure TcpStartup ;
    procedure TcpCleanup ;
    procedure Log(str: string) ;
    procedure MakeConnect ;
    procedure Disconnect;
  end;

threadvar
  s: string[16] ;
  numchars: integer ;
  bytecnt: integer ;
  RecThreadRunning: boolean ;

var
  Form1: TForm1;
  deb: boolean;
  Model: TModel ;


implementation


{$R *.dfm}

procedure TForm1.Disconnect;
begin
    ...
end;
(*------------------------------------*)
procedure TForm1.FormCreate(Sender: TObject);
begin
with TDSP3270.Create(self) do
  begin
    Parent := self;
    Align := alClient;
    ConnectHostName :=('145.70.16.2');
    OnSendData:= DSP32701SendData;
    Caption := '...';
    Left := 0;
    Top := 0;
    {...}
  end;
end;
(*------------------------------------*)


{ RecvThrd }

constructor RecvThrd.Create(ios: TSocket; dsp: TDSP3270);
var
  i: integer ;
begin
  FreeOnTerminate := True ;
  DSP3270:=dsp;
  IOSocket := ios ;
  numchars := 0 ;
  for i := 1 to 16 do
    s[i] := chr(0) ;
  inherited Create(False) ;  { dont run thread yet }
end ;
(*------------------------------------*)
procedure RecvThrd.Execute;
type
  PTelCmd = ^TTelCmd ;
  TTelCmd = packed record
    c_iac: Byte ;
    c_cmd: Byte ;
    c_func: Byte ;
  end ;
  PTelTermCmd = ^TTelTermCmd ;
  TTelTermCmd = packed record
    c_iac:  Byte ;
    c_sb:   Byte ;
    c_term: Byte ;
                 ......................

(*------------------------------------*)
procedure TForm1.MakeConnect;
type
  TPint = ^Longint ;
var
  err: integer ;
  phost: PHostEnt ;
  ina: TInAddr ;
  lina: TInAddr ;
  pint: TPint ;
  RemoteHostName: TPath ;
  PRemoteHostName: PChar ;
  LocalHostName: TPath ;
  PLocalHostName: PChar ;
  LocalAddr: TSockAddrIn ;
  psaddr: PSockAddr ;
  RemoteAddr: TSockAddrIn ;
  pServAddr: PServEnt ;
  usPort: u_short ;
  InitCmd: string ;
  NonBlocked: u_long ;
begin
  TcpStartup() ;
  if deb then
    Log('TCP Started.') ;
  soc := socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) ;
  if soc = INVALID_SOCKET then
    begin
      Log('Error socket invalid.') ;

 ....................
   
  RecvThrd.Create(soc, DSP32701);                       //at this line i am getting the error
  { send CR LF to get server started }
  DSP32701SendData(self,InitCmd);
   ....................

                        end ;
                    end
                  else
                    begin
                      Log('Getservbyname error: '
                        +Format('%d',[WSAGetLastError()])) ;
                      Disconnect ;
                    end ;

                end ;
            end ;
        end
      else
        begin
          Log('Get local host error:'
            +Format('%d',[WSAGetLastError()])) ;
          Disconnect ;
        end ;
    end ;
end;

procedure TForm1.TcpCleanup;
var
  err: integer ;
begin
  err := WSACancelBlockingCall() ;
  err := WSACleanup() ;
end ;


procedure TForm1.TcpStartup;
var
  err: integer ;
  VersionReq: word ;
  wsaData: TWSAData ;
begin
  VersionReq := $0101 ;
  err := WSAStartup(VersionReq,wsaData) ;
end ;

procedure TForm1.DSP32701SendData(Sender: TObject; Data: String);
const
  C_CR    = $0A ; { carrage return }
  C_LF    = $0D ; { line feed }
type
  TOutBuf = array[0..4096] of char ;
var
  err: integer ;
  size: integer ;
  pc: PChar ;
  OutBuffer: TOutBuf ;
  i: integer ;
begin
  if EorFlag then
    data := data + Char(IAC) + Char(C_EOR) ;
  pc := @OutBuffer ;
  StrPCopy(pc,data) ;
  size := Length(data) ;
  err := send(soc,OutBuffer,size,0) ;
  if err = SOCKET_ERROR then
    Log('Send error: '
      +Format('%d',[WSAGetLastError()]))
  else
    begin
      if deb then
        begin
          Log('Send: '+Format(' (%d)',[size])) ;
          for i:=0 to (size-1) do
            DumpChar(OutBuffer[i]) ;
          DumpFlush ;
        end ;
    end ;
end;

procedure TForm1.Connect1Click(Sender: TObject);
begin
  MakeConnect;
end;

end.


Peter
0
Comment
Question by:peterkiers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 8

Expert Comment

by:RickJ
ID: 16925301
Hello,
It is really hard to make sense of the MakeConnect procedure, your begin..ends dont seem to match. You seem to have to many end, you should check this.
And procedure RecvThrd.Execute, I am thinking that this should have begin...end
Very hard to tell...
0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 16926382
the error
 '.' expected but ')' found"
on the line:
 RecvThrd.Create(soc, DSP32701);
can means a few things, but in your case, it might be that you put
 DSP32701 instead of  DSP3270 (see the extra "1")
take a better look at your cose. your unit is also named  DSP3270, so if there is no  DSP3270 member in the  TForm1, then the unit will be used (the unit is also named  DSP3270)

so botom line is: you have a naming issue. you need to sort that yout yourself.
try following the delphi "rules" on naming:
class members are named: FMemberName:TClassType
method parameters are named: aParameterName:TClassType
and you will have less problems with names that way, plus that you wil know exactly to which you are reffering
0
 
LVL 8

Expert Comment

by:RickJ
ID: 16928153
Sorry, I missed that.
Just to make sure I am not going crazy...
The begin...ends do not match in the MakeConnect do they??
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 28

Expert Comment

by:2266180
ID: 16929104
hi RickJ

you're not going crazy :)
in the original code they should. but in the pasted code they don't because the 2
 ....................
lines represent code that was not pasted. or at least that is the general way to represent code that is left out because it is considered irrelevant.

if I am wrong, I hope pieter will infirm that, but I am pretty sure that I'm right :)
0
 
LVL 8

Expert Comment

by:RickJ
ID: 16929119
You know, I was wondering what the signifigance of the lines was.
Pretty obvious I guess.
Thanks for your time ciuly.
0
 
LVL 28

Expert Comment

by:2266180
ID: 16929131
I see, well, you could ask peter to post the whole procedure. he has done it before. I checked the last few questions, but it seems that he has done some major changes to it.

he will respond eventually. he's probably sleeping or something :)
0
 
LVL 8

Expert Comment

by:RickJ
ID: 16929143
No I dont want him to post any more :)
I just meant that I didnt understand what the ............... was.
I do now.    :)
Sorry if I wasnt clear.
Thanks.
0
 
LVL 28

Expert Comment

by:2266180
ID: 16929529
oh, I see :)
well no problem, glad you got it. you'll see those dots around here ;) at least I use it pretty often
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question