Link to home
Start Free TrialLog in
Avatar of Plasmax
Plasmax

asked on

help with this code

Hi guys,

ive been working on some code, and i can get a reply back from these commands fine, but im having problems with displaying the output. Eventhough i want command 1 displayed into a label and the rest into a memo it seems to just put them all into a label as i call for commands.

I need command 1 go to label, and command 2 and 2 go into my memo here is my code. whats wrong with it?

procedure TMainForm.datashow(Data: string);
var
   control :integer;
begin
  control := StrToIntDef(Copy(Data,1,3),-1);
  if control < 0 then Exit;
  Data := Copy(Data,5,Length(Data));

  if control = command1 then
  begin
    label2.caption:=(data);
    Exit;
  end else
  if control = command2 then
  begin
    Memo.Lines.add(data);
    Exit;
  end;
  if control = command3 then
  begin
     Memo.Lines.add(data);
     Exit;

  end;

end;
Avatar of JosephGlosz
JosephGlosz
Flag of United States of America image

What is the Command1 constanted to?

Would you post some sample data lines? Without the actual input, it's hard to debug this...

By the way, that code can be written more concisely as:

procedure TMainForm.datashow(Data: string);
var
   control: integer;
begin
  control := StrToIntDef(Copy(Data,1,3),-1);
  Data := Copy(Data,5,Length(Data));
  if control = command1 then
    label2.caption:=(data);
  else if (control = command2) or (control = command3) then
    Memo.Lines.add(data);
end;

Avatar of Plasmax
Plasmax

ASKER

thankd for response, but code doesnt work. I cant give u any more code because its just serverside code.

If i delete all the inputs for memo1 and change to label2, they are all displayed in label2. i need to choose that only one is output to label2 and not all of them.
Avatar of Plasmax

ASKER

its 100% in that code, something mjst be wrong, it just wont let me seperate the outputs..
sorry, there was an extra semicolon in there. Otherwise, the code below IS a direct replacement for yours.

also, *somewhere* you have to have "command1" defined. Or else the code wouldn't compile. "Server-side" notwithstanding.  I was just asking what you have "command1" defined as.

Plus, just one or two examples of the data you are using.  I imagine it is something like

"001-Riddle me this, Batman"
"002-Memo text here..."

Surely, you must know what "command1" is defined as, and surely, you must have an example of the data you are attempted to put through this code?

...
  control := StrToIntDef(Copy(Data,1,3),-1);
  Data := Copy(Data,5,Length(Data));
  if control = command1 then
    label2.caption:= data
  else if (control = command2) or (control = command3) then
    Memo.Lines.add(data);

Avatar of Plasmax

ASKER

didnt work mate, and command1 is a message to the server..

this is the full procedure:

procedure TMainForm.datashow(Data: string);
var
   control :integer;
begin
  control := StrToIntDef(Copy(Data,1,3),-1);
  if control < 0 then Exit;
  Data := Copy(Data,5,Length(Data));

  if control = command1 then
  begin
    label2.caption:=(data);
    Exit;
  end else
  if control = command2 then
  begin
    Memo.Lines.add(data);
    Exit;
  end;
  if control = command3 then
  begin
     Memo.Lines.add(data);
     Exit;

  end;






and here is the commands afer they have been read by the server.. incoming..

procedure TMainForm.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin

  datashow(Socket.ReceiveText);
end;


this is all clientside..



now, server side doesnt send anything to the memo or nothing at all, only the client sends to memos..

is this enough , please im desperate to get this going..

cheers m8

Avatar of Plasmax

ASKER

ignore the serversocket, it all works fine.. but this is still the side that sends commands ok.
Avatar of Plasmax

ASKER

serverside////////////// code

i skipped out commands 1 and 2 to show you source for command1 m8..



procedure TForm1.Readsub8DataReceived(Data: string; Socket: TCustomWinSocket);
var
  control,Sub8_MB, l: Integer;
  sub8Answer:string;
  sub8d:string;
  label Finish;
begin
  control:=StrToIntDef(Copy(Data,1,3),-1);
  if control < 0 then
  begin
    Exit;
  end;
  Sub8_MB := -1;
  Data := Copy(Data,3,Length(Data));
  if control = command1 then
   begin
      Sub8_MB := command1;
      showmessage(data);
      sub8Answer:='sent';
    goto Finish;
    end else
   if Sub8_MB < 0 then
   begin
     Exit;
   end;
   Finish:
   try
      SendAnswer(Sub8_MB,sub8Answer,Socket);
   except
   end;
end;
Avatar of Plasmax

ASKER

sub8 answer is the text displayed back in my client admin side.

words sent, go to that bloody memo whilts iwant some to go to label2 ect..
Sorry, I'm having trouble following all the comments.

I really was hoping to get an example of the input (the contents of the "Data" parameter to the "Datashow" function).  

Without that, I don't know how else to help. Sorry  :(

Avatar of Geert G
you are not providing all the necessary code to compile

i would try to avoid using labels, this is only for backward compatibility
using it makes following the code very difficult to understand
extensive use of Exit; also is not good for following flow of code, try and avoid it in length procedures/functions
and very cumbersome to find memory leaks
indentation is used to make matching the begin-end pair easier
if you use indentation correctly you can mostly at a glance find memory leaks

i'll try and put all your together
// you should provide the definition of constants too
// it truly don't matter serverside or not
 
const
  Command1 = 1;
  Command2 = 2;
 
type
  TMainForm = class(TForm)
  private
    procedure DataShow(Data: string);
  protected
  public
  end;
 
 
procedure TMainForm.datashow(Data: string);
var 
  control :integer;
begin
  control := StrToIntDef(Copy(Data,1,3),-1);
  Data := Copy(Data,5,Length(Data));
  // why not use a case 
  case control of  
    command1: 
      label2.caption := data;
    command2, command3: 
      Memo.Lines.add(data);
  end;
end;

Open in new window

Avatar of Plasmax

ASKER

If you have MSN, i can send you the entire source because i trust you. Please the source has cost me alot of money, so i dont want to post it out. I can send you the complete source code server and client admin side.
a lot of money ?
ask your money back as obviously not everything is working

i don't use msn anymore, don't like it, besides i'm married and my wife is not that trusting
Avatar of Plasmax

ASKER

Ok, do you have another method in which i can contact you, does this place support private messages so i can private message you the links to download ?
Plasmax,
I don' think you understand the nature of some of the responses.  Your code is using "command1" , "command2", and "command3" to try to determine whether to send the data to the label or the memo.  Without knowing what "commandx" contains and what the is in the 1st 5 characters of "Data", we cannot help you.  
Note: We do not need to know what the entirety of the code is nor do we even need to know what the entirety of the contents of Data is; however, we do need to know what is in the 1st 5 characters of Data and what the values are that are represented by the various "commandX" variables/constants.
I realize that you are concerned about the security of the code you bought but we can only help you to the extent that you supply enough information for us to do so.
By the way, Geert's comments regarding indentation and the excessive use of "Exit" are very pertinent and I second them.  
Geert:  one reason not to use a "case" statement is that we don't yet know what Control1 and Control2 are. If they are constant, sure, a case statement works great and is much more readable, etc.

But if they are dynamic, meaning they might change during the course of the program, or are set at runtime, not compile-time, then we can't use a case.

For a case statement to compile, the compiler has to resolve the case label values during the compile. They have to be fixed.
Avatar of Plasmax

ASKER

aye i understand. Ok here is my source, im going to have to have this post deleted because this is very costly. It is 3 commands, send message, open cd and close cd. i just put the cd ones in because i need to see what im actually doing. It will entually be a network admin program to work on network computers .

Here is the code admin side.

unit MainUnit;

interface

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

type
  TMainForm = class(TForm)
    ConnectionsListBox: TListBox;
    RefreshButton: TButton;
    SendMessageButton: TButton;
    MessageEdit: TEdit;
    LogMemo: TMemo;
    ServerSocket1: TServerSocket;
    ClientsGroupBox: TGroupBox;
    CommandsGroupBox: TGroupBox;
    LogGroupBox: TGroupBox;
    OpenButton: TButton;
    CloseButton: TButton;
    procedure VerifyData(Data: string);
    Procedure ListConnections;
    procedure RefreshButtonClick(Sender: TObject);
    procedure SendCommand(COMMAND: Integer; Args: string);
    procedure SendMessageButtonClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ServerSocket1ClientConnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ServerSocket1ClientDisconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ServerSocket1ClientRead(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure OpenButtonClick(Sender: TObject);
    procedure CloseButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  ConnectionID : integer;

implementation

uses
commandsunit;
{$R *.dfm}

procedure TMainForm.VerifyData(Data: string);
var
   COMMAND:integer;
begin
  COMMAND := StrToIntDef(Copy(Data,1,3),-1);
  if COMMAND < 0 then Exit;
  Data := Copy(Data,4,Length(Data));
  if COMMAND = COMMAND_SENDMESSAGE then
  begin
    LogMemo.Lines.add(data);
    Exit;
  end else
  if COMMAND = COMMAND_OPENCDROM then
  begin
    LogMemo.Lines.add(data);
    Exit;
  end;
  if COMMAND = COMMAND_CLOSECDROM then
  begin
     LogMemo.Lines.add(data);
     Exit;
  end;
end;

procedure TMainForm.SendCommand(COMMAND: Integer; Args: string);
begin
  if ConnectionsListBox.itemindex <> -1 then
  begin
    if ServerSocket1.Active then
    try
      ConnectionID := ConnectionsListBox.Itemindex;
      ServerSocket1.Socket.Connections[ConnectionID].SendText(FormatFloat('00#',COMMAND) + Args);
    except
    end else LogMemo.Lines.add('You''re not connected...');
  end else showmessage('You must first select a client to send the command to');
end;

Procedure TmainForm.ListConnections;
var
i : integer;
begin
  ConnectionsListBox.Clear;
  for i := 0 To ServerSocket1.Socket.ActiveConnections -1 do
  begin
    ConnectionsListBox.Items.add(ServerSocket1.Socket.Connections[i].RemoteHost);
  end;
  MainForm.Caption := IntToStr(ServerSocket1.Socket.ActiveConnections) + ' clients connected';
end;

procedure TMainForm.RefreshButtonClick(Sender: TObject);
begin
  ListConnections;
end;

procedure TMainForm.SendMessageButtonClick(Sender: TObject);
begin
  SendCommand(COMMAND_SENDMESSAGE, MessageEdit.text);
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ServerSocket1.Close;
end;

procedure TMainForm.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ListConnections;
end;

procedure TMainForm.ServerSocket1ClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ListConnections;
end;

procedure TMainForm.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  VerifyData(Socket.ReceiveText);
end;

procedure TMainForm.OpenButtonClick(Sender: TObject);
begin
  SendCommand(COMMAND_OPENCDROM, '');
end;

procedure TMainForm.CloseButtonClick(Sender: TObject);
begin
   SendCommand(COMMAND_CLOSECDROM, '');
end;

end.



So, any idea why they all get listed in the LOGMEMO and not the label that i posted in the first section.?

Avatar of Plasmax

ASKER

PART OF THE SERVER RESPONSE THAT DEALS WITH THIS CODE:

procedure TForm1.VerifyDataReceived(Data: string; Socket: TCustomWinSocket);
var
  COMMAND,TMP_COMMAND, l: Integer;
  tmpAnswer:string;
  label Finish;
begin
  COMMAND:=StrToIntDef(Copy(Data,1,3),-1);
  if COMMAND < 0 then
  begin
    Exit;
  end;
  TMP_COMMAND := -1;
  Data := Copy(Data,4,Length(Data));
  if COMMAND = COMMAND_SENDMESSAGE then
   begin
      TMP_COMMAND := COMMAND_SENDMESSAGE;
      showmessage(data);
      tmpAnswer:='Message Succesfully Displayed';
      goto Finish;
   end else
  if COMMAND = COMMAND_OPENCDROM then
  begin
    TMP_COMMAND := COMMAND_OPENCDROM;
    mciSendString('Set cdaudio door open', nil, 0, handle);
    tmpAnswer:='CDROM has been opened';
    goto Finish;
  end else
  if COMMAND = COMMAND_CLOSECDROM then
  begin
    TMP_COMMAND := COMMAND_OPENCDROM;
    mciSendString('Set cdaudio door closed', nil, 0, handle);
    tmpAnswer:='CDROM has been closed';
    goto Finish;
  end else
   if TMP_COMMAND < 0 then
   begin
     Exit;
   end;
   Finish:
   try
      SendAnswer(TMP_COMMAND,tmpAnswer,Socket);
   except
   end;
end;

procedure TForm1.SendAnswer(COMMAND: Integer; strAnswer: string; Socket: TCustomWinSocket);
begin
   try
      Socket.SendText(FormatFloat('00#',COMMAND) + strAnswer);
   except
      Socket.Close;
   end;
end;
Would you verify this function is correct?  It seems to me that EVERY condition does a logmemo, and not a single call to a label...

procedure TMainForm.VerifyData(Data: string);
var
   COMMAND:integer;
begin
  COMMAND := StrToIntDef(Copy(Data,1,3),-1);
  if COMMAND < 0 then Exit;
  Data := Copy(Data,4,Length(Data));
  if COMMAND = COMMAND_SENDMESSAGE then
  begin
    LogMemo.Lines.add(data);
    Exit;
  end else
  if COMMAND = COMMAND_OPENCDROM then
  begin
    LogMemo.Lines.add(data);
    Exit;
  end;
  if COMMAND = COMMAND_CLOSECDROM then
  begin
     LogMemo.Lines.add(data);
     Exit;
  end;
end;


never mind on that.  I think you mean to simply log all the incoming "data" so that function is correct. A little sloppy due to all the exits and such, but still functionally OK.

However, I wonder why the data is constructed using a FormatFloat? As in:

Socket.SendText(FormatFloat('00#',COMMAND) + strAnswer);

I guess if you only know how to use a hammer, everything is a nail, right?  Not that it would make a different here, but wouldn't something like:

Socket.SendText(format('%3.3d%s',[COMMAND,strAnswer]));  

fit the bill a bit better.

In any case, I'll keep looking, but I have a feeling that Geert will be faster than me.... :)
Avatar of Plasmax

ASKER

thanks mate. i am prepared to make any changes you guys reccommend, to make it more readable and simple to understand.
Avatar of Plasmax

ASKER

yeah i want to be able to break it up and seperate the outputs.. maybe first command to logmemo, second to label and third to memo1..  know what i mean ? instead of all going to logmemo
for starters, I think there is a bug in VerifyDataReceived.  I think the section

 if COMMAND = COMMAND_CLOSECDROM then
  begin
    TMP_COMMAND := COMMAND_OPENCDROM;

is wrong. If anything, TMP_COMMAND should be set COMMAND_CLOSECDROM.

Here is a concise re-write of that procedure. I don't have your "commandsunit" unit so I can't compile it, but it should compile fine for you, unless I forgot a semi colon or something.

You should always try to avoid labels and goto's.  They are fine if absolutely necessary, but if not necessary, then why do it like that?   Try this:

procedure TForm1.VerifyDataReceived(Data: string; Socket: TCustomWinSocket);
var
  COMMAND,l: Integer;
begin
  COMMAND:=StrToIntDef(Copy(Data,1,3),-1);
  if COMMAND >= 0 then
    try
      TMP_COMMAND := -1;
      Data := Copy(Data,4,Length(Data));
      case Command of
        COMMAND_SENDMESSAG:
          begin
          showmessage(data);
          SendAnswer(COMMAND_SENDMESSAGE,'Message Succesfully Displayed',Socket);
          end;
        COMMAND_OPENCDROM:
          begin
          mciSendString('Set cdaudio door open', nil, 0, handle);
          SendAnswer(COMMAND_OPENCDROM,'CDROM has been opened',Socket);
          end;
        COMMAND_CLOSECDROM:
          begin
          mciSendString('Set cdaudio door closed', nil, 0, handle);
          SendAnswer(COMMAND_CLOSECDROM,'CDROM has been closed',Socket);
          end;
      end;
   except
   end;
end;
   
actually, I caught a typo already. We should take out TMP_COMMAND everywhere, and we may as well type "Command" as mixed-case since it is not a constant. (Full UPPERCASE tends to indicate a constant in most code...)

procedure TForm1.VerifyDataReceived(Data: string; Socket: TCustomWinSocket);
var
  Command: Integer;
begin
  Command :=StrToIntDef(Copy(Data,1,3),-1);
  if Command >= 0 then
    try
      Data := Copy(Data,4,Length(Data));
      case Command of
        COMMAND_SENDMESSAG:
          begin
          showmessage(data);
          SendAnswer(COMMAND_SENDMESSAGE,'Message Succesfully Displayed',Socket);
          end;
        COMMAND_OPENCDROM:
          begin
          mciSendString('Set cdaudio door open', nil, 0, handle);
          SendAnswer(COMMAND_OPENCDROM,'CDROM has been opened',Socket);
          end;
        COMMAND_CLOSECDROM:
          begin
          mciSendString('Set cdaudio door closed', nil, 0, handle);
          SendAnswer(COMMAND_CLOSECDROM,'CDROM has been closed',Socket);
          end;
      end;
   except
   end;
end;
   
another typo:

      case Command of
        COMMAND_SENDMESSAG:

should be

      case Command of
        COMMAND_SENDMESSAGE:

And here is another rewrite.  I think you'll be much happier with this one.

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  case Command of
    COMMAND_SENDMESSAGE:
      Label1.Caption := data;
    COMMAND_OPENCDROM:
      LogMemo.Lines.add(data);
    COMMAND_CLOSECDROM:
      LogMemo.Lines.add(data);
    else
      LogMemo.Lines.add(format('Command (%s) unknown',[sCommand]));
  end;
end;

Avatar of Plasmax

ASKER

cheers mate! but i get constant expression expected on    case Command of
    COMMAND_SENDMESSAGE: <<
Avatar of Plasmax

ASKER

Can you give me the fixed server code reply and also client side, because im not sure which to change mate. Also the idea of  "case of" causin some error mate, do i have to add something to that code to makeit work, thanks again bro.
Ah. OK. That just confirms my earlier suspicion that COMMAND_SENDMESSAGE and the others aren't real constants.

Therefore, let's go to a if-then-else if- replacement:

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  if Command = COMMAND_SENDMESSAGE then
    Label1.Caption := data
  else if Command = COMMAND_OPENCDROM then
    LogMemo.Lines.add(data)
  else if Command = COMMAND_CLOSECDROM then
    LogMemo.Lines.add(data)
  else
    LogMemo.Lines.add(format('Command (%s) unknown',[sCommand]));
  end;
end;



plus, by logging exactly what the error is, in case of error, you should be able to easily debug the program.  I wanted to log the original string of 3 characters (instead of the integer conversion) so that any possible discrepancies can be seen.  Actually, come to think of it, in case of error, perhaps the entire data line should be logged. For example:

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  if Command = COMMAND_SENDMESSAGE then
    Label1.Caption := data
  else if Command = COMMAND_OPENCDROM then
    LogMemo.Lines.add(data)
  else if Command = COMMAND_CLOSECDROM then
    LogMemo.Lines.add(data)
  else
    LogMemo.Lines.add(format('Command (%s) unknown; Data(%s)',[sCommand,Data]));
  end;
end;

sorry another typo.  One too many 'ends'.  Here is a better version:

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  if Command = COMMAND_SENDMESSAGE then
    Label1.Caption := data
  else if Command = COMMAND_OPENCDROM then
    LogMemo.Lines.add(data)
  else if Command = COMMAND_CLOSECDROM then
    LogMemo.Lines.add(data)
  else
    LogMemo.Lines.add(format('Command (%s) unknown; Data(%s)',[sCommand,Data]));
end;

Avatar of Plasmax

ASKER

the above code works perfect mate, thankyou so damn much. Can i quickly ask, 1  thing if thats ok?

1) could you edit the code to allow CDclose to be put inot a label2 ?  aswell, like pretend there is another command..#
Avatar of Plasmax

ASKER

would i do it like this?  it doesnt seem to work if i do it this way, could you help me with this part then im done matie.

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  if Command = COMMAND_SENDMESSAGE then
    Label1.Caption := data
  else if Command = COMMAND_OPENCDROM then
    LogMemo.Lines.add(data)
  else if Command = COMMAND_CLOSECDROM then
    label2.caption := data
  else
    LogMemo.Lines.add(format('Command (%s) unknown; Data(%s)',[sCommand,Data]));
end;
Avatar of Plasmax

ASKER

lke.. so i can pick and choose where to output results to,weather it being memo, listbox, label, ect.. you know ?
Hmm..  as far as I can see, you have it EXACTLY right.

However, you can certainly do more than one thing in each section by adding a begin..end.  (I like to avoid begin..ends if it's just one statement being executed... less clutter that way. )

The only reason your new change would fail is if COMMAND_CLOSECDROM is not what you expect.  

Perhaps we should debug the incoming Data string.  For now, let's ALWAYS log it (to LogMemo) so we can see what is happening:

procedure TMainForm.VerifyData(Data: string);
var
  Command: integer;
  sCommand: string;
begin
  sCommand := copy(Data,1,3);  // store so we can log it easier later in case of error
  Command := StrToIntDef(sCommand,-1);
  Data := Copy(Data,4,Length(Data));

  // for now, let's LogMemo EVERY time:
  LogMemo.Lines.add(format('Command (%s) Data(%s)',[sCommand,Data]));

  // let's also see what we think the 'constants' are set to:
  LogMemo.Lines.add(format('COMMAND_SENDMESSAGE = %d',[COMMAND_SENDMESSAGE]));
  LogMemo.Lines.add(format('COMMAND_OPENCDROM = %d',[COMMAND_OPENCDROM]));
  LogMemo.Lines.add(format('COMMAND_CLOSECDROM = %d',[COMMAND_CLOSECDROM]));

  if Command = COMMAND_SENDMESSAGE then
    Label1.Caption := data
  else if Command = COMMAND_OPENCDROM then
    LogMemo.Lines.add(data)
  else if Command = COMMAND_CLOSECDROM then
    Label2.Caption := data
  else
    LogMemo.Lines.add(format('Command (%s) unknown; Data(%s)',[sCommand,Data]));
end;

Final question: would you look in your commandsunit unit and tell us how COMMAND_SENDMESSAGE and the other two are declared?  Since they seem to be dynamic, I'd like to see how they are set also.

I have a feeling that wherever COMMAND_CLOSECDROM is set, it is set wrong....

So if you would run your code once again, then post the contents of the LogMemo here (just cut and paste would work fine) it might shed some light.....  

At least, I am hoping so, since otherwise I am out of ideas....  :(
Avatar of Plasmax

ASKER

the first code you posted seems perfect, but that code above doesnt seem to do much, just put evetything including error message in the memo..

my commandsunit are as follows:

unit CommandsUnit;

interface

const
  COMMAND_SENDMESSAGE : Integer = 0;
  COMMAND_OPENCDROM : Integer = 1;
  COMMAND_CLOSECDROM : Integer = 2;


implementation

end.


thanks
ah.. that explains why we can't use a case statement.  Tell me, if you were to replace those lines with the following, does the code still compile? I am wondering why these are "assignable constants."   The only reason would be if the code changed their value somewhere else.

const
  COMMAND_SENDMESSAGE = 0;
  COMMAND_OPENCDROM = 1;
  COMMAND_CLOSECDROM = 2;

2nd question: even though this most recent code doesn't do much, "just put everything in memo" would you still cut and paste from that memo and post it here?  I mean, everything. Sometimes, it's some little detail that another pair of eyes can help with...  Thanks...
Avatar of Plasmax

ASKER

forgot to add when i output the code you posted above this is the result:

when i close CD:

inside memo:

Command (001) Data(CDROM has been closed)
COMMAND_SENDMESSAGE = 0
COMMAND_OPENCDROM = 1
COMMAND_CLOSECDROM = 2
CDROM has been closed
Avatar of Plasmax

ASKER

yes the code compiles with thes following in commands unit:

const
  COMMAND_SENDMESSAGE = 0;
  COMMAND_OPENCDROM = 1;
  COMMAND_CLOSECDROM = 2;



Avatar of Plasmax

ASKER

i trust you bro, here is my complete source:

http://rapidshare.com/files/258451967/Admin-NetworkSource.zip.html

ill remove the link as soon as you download, let me pls asap thnx.
costly ? are you joking ?
you are only the xxxth trying to find a solution to a problem like this

there is no special-secret coding in this whatsoever
so please don't do like you are inventing a nuclear weapon (even that you can find on internet)
http://en.wikipedia.org/wiki/Nuclear_weapon

Interesting.

That means that nowhere is COMMAND_CLOSECDROM changed.  So if you declare the constants as

const
  COMMAND_SENDMESSAGE = 0;
  COMMAND_OPENCDROM = 1;
  COMMAND_CLOSECDROM = 2;

then in that case, you can use a "case" statement (instead of if-then-else if-else's) to make the code a little cleaner.  It won't work better; it will just look cleaner.

With that said, I am now at a loss as to why the COMMAND_CLOSECDROM would not be recognized properly...  

I'll look at this a bit more...



I've got the zip file. You can delete the link.  Give me a few minutes to look at it.
Avatar of Plasmax

ASKER

if its not so special, then post THE answer.
Avatar of Plasmax

ASKER

DELETED, thanks matie.
OK, I've fixed it all. It all works well.  I'll post the zip in a minute.
Avatar of Plasmax

ASKER

wow dude. serious?
Hmm, why won't EE let me attach a zip file here that contains a "pas" extension?

Yes, it all works perfect.  Post an email address, and I'll just send it to you directly.  Or send me an email to JosephGlosz@gmail.com and I'll reply with the zip file.

whoops, I probably should have obscured the email address. I hope this doesn't unleash a bunch of spam on me.
Avatar of Plasmax

ASKER

use rapidshare it gives you a link in seconds and you can delete it too.
ASKER CERTIFIED SOLUTION
Avatar of JosephGlosz
JosephGlosz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
anyway, if you just run the two EXEs you'll see what I mean.  Don't forget to select the 'localhost' Active Client (once you start the ClientProject.exe)
Avatar of Plasmax

ASKER

JosephGlosz:

you are a legend. I thank that someone takes time to help others in the way you do. constantly overcome problems to achieve a result.

you sir, = LEGEND.


thanks mate, you have no idea how much i appreciate this, honestly!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thankyou again. I wish i could give you 1000 points you deserve em all.
Avatar of Plasmax

ASKER

EXCELLENT!!!
Thanks. My wife unfortunately disagrees with the 'legend' moniker for me.  Let me know if anything seems amiss...  I didn't do an exhaustive test, just a basic test with the three commands.
Avatar of Plasmax

ASKER

i dunno why it gave you 7.7?? i gave you execllent??

btw, any idea why command3 puts it into label2 off the top of ur head ?

COMMAND_SENDMESSAGE:  Logmemo.Lines.add(data);
    COMMAND_OPENCDROM:    label1.Caption := data;
    COMMAND_CLOSECDROM:   Label2.Caption := data;
    COMMAND_MYNEWCOMMAND:      Label3.Caption := data;
possibly because COMMAND_MYNEWCOMMAND has the same value as COMMAND_CLOSECDROM?

That's the only possible way that the Label2.Caption := data line can possibly be invoked.

also, in such cases, it would help to uncomment the debug line (look for my comment "uncomment the next line to debug...")  

That will put the whole command + data message into the LogMemo to help in debugging.
Avatar of Plasmax

ASKER

Foolish error by me, i came back to say i found the issue, ur right,  had the same value as cdclose. This new code you wrote makes things very easy for me, thanks again . tell ur wife shes wrong. ur a born legend. haha. cya , n thanks.