Solved

Testing my component dynamicly with a connection

Posted on 2006-06-16
8
241 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
Comment Utility
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:
ciuly earned 500 total points
Comment Utility
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
Comment Utility
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:ciuly
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Expert Comment

by:RickJ
Comment Utility
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:ciuly
Comment Utility
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
Comment Utility
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:ciuly
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

8 Experts available now in Live!

Get 1:1 Help Now