Q&A

  • NMFTP 땜시 미티겠어요.
다름이 아니오라 분명히 이상이 없는 것 같은데 계속 Access Violation이 생기고, 두번째로 실행하면 CPU가 100%를 달립니다.

어찌해야 좋을까요?


<DLL 모듈>
unit WMFTPImpl;

interface

uses
  Sysutils,
  Dialogs,
  Psock,
  NMFtp;

type
        FTPRESULT = record
                Success : Boolean;
                TargetHost : String;
                TargetPort : Integer;
                User : String;
                Password : String;
                Elapsed : Integer;
                LastMessage : String;
        end;


//Define procedure, function
function CheckFTP(Host_ : String; Port_ : Integer; User_, Password_ : String) : FTPRESULT; stdcall;


implementation

var
        NMFTP1 : TNMFTP;


function CheckFTP(Host_ : String; Port_ : Integer; User_, Password_ : String) : FTPRESULT; stdcall;
var
        reslt : FTPRESULT;
        start_ : TDateTime;
        end_ : TDateTime;
begin
        Result := reslt;

        Result.Success := false;
        Result.TargetHost := Host_;
        Result.TargetPort := Port_;
        Result.User := User_;
        Result.Password := Password_;
        Result.Elapsed := 0;

        try
                NMFTP1 := TNMFTP.Create(nil);

                with NMFTP1 do begin
                        try
                                start_ := Now;

                                Host := Host_;
                                Port := Port_;
                                UserID := User_;
                                Password := Password_;
                                TimeOut := 10000;
                                Connect;

                                end_ := Now;
                                Result.Elapsed := StrToInt(FormatDateTime('z', end_ - start_));
                                Result.Success := true;
                                Result.LastMessage := 'Success';

                                //Mode(MODE_BYTE);
                                //ChangeDir(Edit3.Text);
                                //List;
                        except
                        {
                                on ESockError do
                                        Result.LastMessage := 'Connection Failed';
                        }
                                on e : Exception do
                                        //ShowMessage(ex.message);
                                        Result.LastMessage := e.message;
                        end;
                end;
        finally
                if NMFTP1.Connected then
                        NMFTP1.Disconnect;

                NMFTP1.Free;
        end;
end;


end.




<호출하는 놈>
//FTP 검사결과
type
        FTPRESULT = record
                Success : Boolean;
                TargetHost : String;
                TargetPort : Integer;
                User : String;
                Password : String;
                Elapsed : Integer;
                LastMessage : String;
        end;

.
.
.
//FTP Test
procedure TForm1.SpeedButton3Click(Sender: TObject);
var
        reslt : FTPRESULT;
begin
        Memo3.Clear;

        reslt := CheckFTP(Edit4.Text, StrToInt(Edit5.Text), Edit6.Text, Edit7.Text);

        if reslt.Success then
        begin
                Memo3.Lines.Add('[Host] : ' + reslt.TargetHost);
                Memo3.Lines.Add('[Port] : ' + IntToStr(reslt.TargetPort));
                Memo3.Lines.Add('[UserID] : ' + reslt.User);
                Memo3.Lines.Add('[Password] : ' + reslt.Password);
                Memo3.Lines.Add('[Elapsed] : ' + IntToStr(reslt.Elapsed) + 'ms');
                Memo3.Lines.Add('[Message] : ' + reslt.LastMessage);
        end
        else
        begin
                {
                if reslt.LastMessage = '' then
                        ShowMessage('Last Message is NIL')
                else
                        ShowMessage('[Message] : ' + reslt.LastMessage);
                }
//이 부분에서 reslt.LastMessage를 참조하면 에러가 발생하네요...
                Memo3.Lines.Add('[Failed] : ' + reslt.TargetHost + ':' + IntToStr(reslt.TargetPort));
                Memo3.Lines.Add('[Message] : ' + reslt.LastMessage);
        end;


end;


좀 알려주시렵니까?
혹시나 record에서 PChar땜시 아닌가 해서 String으로 바꾸었는데도 똑같네요...
0  COMMENTS