Solved

Testing my component dynamicly with a connection

Posted on 2006-06-16
8
244 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now