Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Procedure problem.

Posted on 2006-06-06
4
Medium Priority
?
265 Views
Last Modified: 2012-05-05
Hi Experts,

In my previous question I have asked how to connect a procedure that is stored
in my component TDSP3270 to a procedure (called SendData) that is stored on the main form.

I got this answer:

type
  TOnSendData       =  procedure(Sender: TObject; Data: String) of object;
  TDSP3270         =  class(TComponent)
  private
      Private declarations
     FOnSendData:   TOnSendData;
  protected
      Protected declarations
  public
      Public declarations
  published
      Published declarations
     property       OnSendData: TOnSendData read FOnSendData write FOnSendData;
  end;

type
  TForm1            = class(TForm)
     procedure      FormCreate(Sender: TObject);
  private
      Private declarations
  public
      Public declarations
     procedure      OnSendData(Sender: TObject; Data: String);
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TDSP3270.DataOut(key: byte);
var obuf: string ;
     ba1, ba2: byte ;
begin
  ReadModified(obuf) ;
  rc2sba(fCsrRow,fCsrCol,ba1,ba2) ;
  obuf := Char(key) + Char(ba1) + Char(ba2) + obuf ;
  LockKeyBoard('SYSTEM',NOALARM) ;
  if Assigned(FOnSendData) then FOnSendData(Self, obuf);
end ;

procedure TForm1.FormCreate(Sender: TObject);
begin
 DSP32701.OnSendData:= DSP32701SendData;
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;

But I forgot to tell that there is another procedure (MakeConnect) on the main form that calls
the procedure SendData also!

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.') ;
      socOpen := False ;
    end
  else
    begin
      if deb then
        Log('Socket opened OK.') ;
      socOpen := True ;
    end ;

  { get foreign host name and addr }
  PRemoteHostName := @RemoteHostName ;
  StrPCopy(PRemoteHostName,ConnectHostName) ;
  phost := gethostbyname(PRemoteHostName) ;
  if phost = nil then
    begin
      Log('Error, failed to find host.') ;
      Disconnect ;
    end
  else
    begin
      if deb then
        begin
          Log('Foreign host name: '
            +PChar(phost^.h_name)) ;
          Log('    Address type: '
            +format('%x',[phost^.h_addrtype])) ;
          Log('    Address length: '
            +format('%d',[phost^.h_length])) ;
        end ;
      pint := Pointer(phost^.h_addr_list^) ;
      ina.s_addr := pint^ ;
      if deb then
        Log('    Foreign host address: '
          +PChar(inet_ntoa(ina))) ;

      { get local host name and addr }
      PLocalHostName := @LocalHostName ;
      if gethostname(PLocalHostName,MAX_PATH) <> SOCKET_ERROR then
        begin
          phost := gethostbyname(PLocalHostName) ;
          if phost = nil then
            begin
              Log('Error, failed to find local host.') ;
              Disconnect ;
            end
          else
            begin
              if deb then
                begin
                  Log('Local host name: '
                    +PChar(phost^.h_name)) ;
                  Log('    Address type: '
                    +format('%x',[phost^.h_addrtype])) ;
                  Log('    Address length: '
                    +format('%d',[phost^.h_length])) ;
                end ;
              pint := Pointer(phost^.h_addr_list^) ;
              lina.s_addr := pint^ ;
              if deb then
                Log('    Local host address: '
                  +PChar(inet_ntoa(lina))) ;

              { bind socket to addr }
              LocalAddr.sin_family := AF_INET ;
              LocalAddr.sin_addr.s_addr := lina.s_addr ;
              LocalAddr.sin_port := htonl(INADDR_ANY) ;
              psaddr := Pointer(@LocalAddr) ;
              err := bind(soc,psaddr^,SizeOf(LocalAddr)) ;
              if err = SOCKET_ERROR then
                begin
                  Log('Bind error: '
                    +Format('%d',[WSAGetLastError()])) ;
                  Disconnect ;
                end
              else
                begin
                  if deb then
                    Log('Bind successful') ;

                  { get service port }
                  pServAddr := getservbyname('telnet','tcp') ;
                  if pServAddr <> nil then
                    begin
                      if deb then
                        begin
                          Log('Remote Service Info.:') ;
                          Log('    Name: '+PChar(pServAddr^.s_name)) ;
                          Log('    Port: '+Format('%d',[ntohs(pServAddr^.s_port)])) ;
                        end ;
                      usPort := pServAddr^.s_port ;

                      { connect to server }
                      RemoteAddr.sin_family := AF_INET ;
                      RemoteAddr.sin_addr.s_addr := ina.s_addr ;
                      RemoteAddr.sin_port := usPort ;
                      psaddr := Pointer(@RemoteAddr) ;
                      err := connect(soc,psaddr^,SizeOf(RemoteAddr)) ;
                      if err = SOCKET_ERROR then
                        begin
                          Log('Connect error: '
                            +Format('%d',[WSAGetLastError()])) ;
                          Disconnect ;
                        end
                      else
                        begin
                          if deb then
                            Log('Connected.') ;
                          RecvThrd.Create(soc, DSP32701);
                          { send CR LF to get server started }
                   //       SendData(InitCmd) ;                                 //Error at this line

                        end ;
                    end
                  else


At line SendData(InitCmd) I got the following error:
[Error] Main.pas(686): Undeclared identifier: 'SendData'
Who can help me with this problem?

Thank you in advanced,

Greetings,

Peter Kiers
0
Comment
Question by:peterkiers
  • 2
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 2000 total points
ID: 16849610
If I understand correctly, you will have to replace
       SendData(InitCmd) ;                                 //Error at this line
with
DSP32701SendData(self,InitCmd);
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16849793
Oke, I have done that, and now I don't have an error anymore
but my component still doesn't work!!!

When I put my component on the form with align = alClient
and assign the event OnSendData to the procedure
TForm1.DSP32701SendData(Sender: TObject; Data: String);
and then when I press F9 to run, I get the logon-screen
of the host, but when I enter the Userid + password and then
press Enter nothing happends.

I need more time to figure out why my component doesn't work.

Peter
0
 
LVL 28

Expert Comment

by:2266180
ID: 16849822
if you haven't done this already, then you should be all means put a logging system in your component and put maybe some flags or compiler directives so it only gets run when you are in debug mode. it helps you find issues faster then stepping through the code in a lot of situations ;)
0
 
LVL 1

Author Comment

by:peterkiers
ID: 16849850
Oke, thank you for your advice.

P.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Screencast - Getting to Know the Pipeline
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

564 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