Recent

Author Topic: Wake On Lan Component: Whats Wrong ?  (Read 8464 times)

renatocrd

  • Newbie
  • Posts: 6
Wake On Lan Component: Whats Wrong ?
« on: April 18, 2009, 07:36:27 pm »
excuse my poor English! :)

my problem is:

I'm trying to write a non-visual component of
"wakeup on lan" with inet and derived from tcomponent.

Lazarus compiles the code normally be reconstructed without errors but when I try to compile some other project comes an error:

SIGSEGV

what is wrong?
following code below to component:



---------------------------------
unit rnswol;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, lnetcomponents;

Type
    TRNSWakeOnLan = Class(TComponent)
          Procedure Execute;

    Private
          FMacAddress: String;
    Protected
          Function WOL(MacAddress: String): Boolean;

    Published
          property MacAddress: String READ FMacAddress WRITE FMacAddress;

    Public
          constructor Create(AOwner: TComponent); override;
          destructor  Destroy; override;
end;

procedure Register;


implementation


Constructor TRNSWakeOnLan.Create(AOwner: TComponent);
Begin

     Inherited Create(AOwner);

end;


Procedure TRNSWakeOnLan.Execute;
Begin

     WOL(MacAddress);

end;


Function TRNSWakeOnLan.WOL(MacAddress: String): Boolean;  // Envia comando para ligar o computador.
Var                                         // Necessita Mac Address e o Computador deve estar
        SendPacket: TLUDPComponent;         // Configurado para Wake On Lan.
        TempMac,
        TempStr    : String;
        WolPacket  : String;
        I,
        J          : Integer;
Begin


     if Length(MacAddress) = 12 then
     Begin

        SendPacket := TLUDPComponent.Create(SendPacket);
        SendPacket.Host := '255.255.255.255';
        SendPacket.Port := 9;
        SendPacket.Connect;

        TempMac := '';
        TempStr := '';


        WolPacket := Chr(StrToInt('$FF')) + Chr(StrToInt('$FF')) + Chr(StrToInt('$FF')) +
                     Chr(StrToInt('$FF')) + Chr(StrToInt('$FF')) + Chr(StrToInt('$FF'));

        MacAddress := StringReplace(MacAddress,':','',[rfReplaceAll]);

        for i := 1 to 16 do
        Begin

                TempMac := TempMac + Chr(strtoint('$' + MacAddress[1] + MacAddress[2])) + Chr(strtoint('$' + MacAddress[3] + MacAddress[4])) + Chr(strtoint('$' + MacAddress[5] + MacAddress[6])) +
                                     Chr(strtoint('$' + MacAddress[7] + MacAddress[8])) + Chr(strtoint('$' + MacAddress[9] + MacAddress[10])) + Chr(strtoint('$' + MacAddress[11] + MacAddress[12]));
        end;


        WolPacket := WolPacket + TempMac;

        SendPacket.SendMessage(WolPacket);

        SendPacket.Destroy;
        SendPacket := Nil;

     end;

end;


Destructor TRNSWakeOnLan.Destroy;
begin

     inherited;

end;


Procedure Register;
Begin

     RegisterComponents('Walker',[trNSWakeOnLan]);

end;


end.
----------------------------------------


Loesje

  • Full Member
  • ***
  • Posts: 168
    • Lazarus Support website
Re: Wake On Lan Component: Whats Wrong ?
« Reply #1 on: April 19, 2009, 01:07:16 pm »
First try to find out on which line the crash occurs.

renatocrd

  • Newbie
  • Posts: 6
Re: Wake On Lan Component: Whats Wrong ?
« Reply #2 on: April 20, 2009, 04:51:10 am »
   
Goodnight to all,
the problem was not the component, which in
signal worked perfectly. The problem
Lazarus was really in that for some
why not compiled any project.

Reinstall Lazarus, installed component
Wakeup on lan and to work normally.
If any of you can test it in linux
be of great help to me.

Thank you all.

 

TinyPortal © 2005-2018