using memo instead of messagebox


hi

am using this code to update my no-ip account
how would i change it so instead of using the message box
send the string for the update using copyurl and get the server response in a memo instead of the messagebox

this is the protocol for no-ip
http://www.no-ip.com/integrate/request

thanks

pete

code below:-

function CopyURL(const URL: String):string;
var
hSession, hURL: HInternet;
settings:string;
buffer: array [0..20] of Char;
bytes_read: DWORD;
begin
hSession := InternetOpen(pchar(url),INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
try
   hURL := InternetOpenURL(hSession, PChar(URL), nil,0,0,0);
   try
      begin
      settings := '';
         repeat
         InternetReadFile(hURL,@buffer,Length(buffer),bytes_read);
         settings := settings + Copy(buffer,1,bytes_read);
         until bytes_read =0;
      InternetCloseHandle(hURL);
      end;
result:=settings;
   finally
   internetCloseHandle(hURL)
   end
finally
InternetCloseHandle(hSession)
end
end;



 procedure TForm1.Button1Click(Sender: TObject);
 var
ip:string;
user:string;
pwd:string;
dns:string;
begin
user:=edit1.text;
pwd:=edit2.text;
dns:=edit3.text;
ip:=edit4.text;

MessageBox(0,pchar(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip)),
'Update No-IP Result:',MB_OK);
//codes:
//status=0 -> no change
//status=1 -> correct uptade
//status=2 -> incorrect dns
//status=3 -> incorrect password
//status=4 -> incorrect username
  end;
LVL 1
peter2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MainiacfreakusCommented:
change this line:
MessageBox(0,pchar(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip)),

to memo1.lines.add(pchar(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip)));

where memo1 is the name of your memo component.

Hope this is what you want.

Mainiacfreakus
0
peter2001Author Commented:
hi thanks

the responce i get from the no-ip server in the memo shows
 
Myaccount.no-ip.info:0  //if no change is needed
Myaccount.no-ip.info:1 //update correct

ect

//codes:
//status=0 -> no change
//status=1 -> correct update
//status=2 -> incorrect dns
//status=3 -> incorrect password
//status=4 -> incorrect username

how would i get the memo to say if for example
Myaccount.no-ip.info:0  show have it say  'no change needed'   instead

i thought something like this

if
memo1.lines.add(pchar(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip)))='Myaccount.no-ip.info:0' then begin memo1.lines.add('no change needed');  

but obvisouly this does not work have you any idea how to do this?

thanks pete
0
MainiacfreakusCommented:
k, will test it...

get back 2 u in an hour or so...

Mainiacfreakus
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

MainiacfreakusCommented:
I am afraid you are going to have to ask someone else...

Unless you can work out why our firewall is blocking the connection... :-(

Mainiacfreakus
0
peter2001Author Commented:
hi

thanks anyway  


i suppose i will have to use the onchange event in the memo

unless anyone else has a better way


0
2266180Commented:
use something like this:

const max=4;
      statusCodes:array[0..max] of string=(
                    'no change',
                    'correct uptade',
                    'incorrect dns',
                    'incorrect password',
                    'incorrect username'
                  );

function getStatusFor(code:char):string;
var c:byte;
begin
  c:=ord(code)-48;
  if c in [0..max] then result:=statusCodes[c]
                   else result:='Unkown result code: '+code;
end;

procedure TForm1.FormCreate(Sender: TObject);
var ip,
    user,
    pwd,
    dns,
    res:string;
begin
  user:='youruser';
  pwd:='yourpassword';
  dns:='yourdns';
  ip:='yourip';
  res:=trim(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip));
  memo1.lines.add(getStatusFor(res[length(res)]));
end;

0
2266180Commented:
btw, I don't know what you use for those values, but you should know that the resultin string is of the form:

'yourdns:<code from 0..4>'#10
and not
'Myaccount.no-ip.info:<code from 0..4>'
unless 'yourdns' value is 'Myaccount.no-ip.info' but even then, you are loosing the terminating #10
0
2266180Commented:
hm... I looked over the protocol and there are some major changes that need to be done to my code :)

here is the final one:

function getStatusFor(code:string):string;
var c:byte;
begin
  try
    c:=strtoint(code);
    case c of
         0      : result:='Success: IP address is current, no update performed';
         1      : result:='Success: DNS hostname update successful';
         2      : result:='Error: Hostname supplied does not exist';
         3      : result:='Error: Invalid username';
         4      : result:='Error: Invalid password';
         5      : result:='Error: To many updates sent. Updates are blocked until 1 hour passes since last status of 5 returned.';
         6      : result:='Error: Account disabled due to violation of No-IP terms of service. Our terms of service can be viewed at http://www.no-ip.com/legal/tos';
         7      : result:='Error: Invalid IP. Invalid IP submitted is improperly formated, is a private LAN RFC 1918 address, or an abuse blacklisted address.';
         8      : result:='Error: Disabled / Locked hostname';
         9      : result:='Error: Host updated is configured as a web redirect and no update was performed.';
         10      : result:='Error: Group supplied does not exist';
         11      : result:='Success: DNS group update is successful';
         12      : result:='Success: DNS group is current, no update performed.';
         13      : result:='Error: Update client support not available for supplied hostname or group';
         14      : result:='Error: Hostname supplied does not have offline settings configured. Returned if sending offline=YES on a host that does not have any offline actions configured.';
         99      : result:='Error: Client disabled. Client should exit and not perform any more updates without user intervention.';
         100: result:='Error: User input error usually returned if missing required request parameters';
         else result:='Unkown result code.';
    end;
  except
    code:=lowercase(code);
    result:='';
    if code='good' then result:='Success: DNS hostname update successful';
    if code='nochg' then result:='Success: IP address is current, no update performed';
    if code='nohost'then result:='Error: Hostname supplied does not exist';
    if code='badauth' then result:='Error: Invalid username';
    if code='badagent' then result:='Error: Client disabled. Client should exit and not perform any more updates without user intervention.';
    if code='abuse' then result:='Error: Account disabled due to violation of No-IP terms of service. Our terms of service can be viewed at http://www.no-ip.com/legal/tos';
    if result='' then result:='Unkown result code.';
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
var ip,
    user,
    pwd,
    dns,
    res,
    status:string;
begin
  user:='youruser';
  pwd:='yourpassword';
  dns:='yourdns';
  ip:='yourip';
  res:=trim(CopyURL('http://dynupdate.no-ip.com/dns?username='+user+'&password='+pwd+'&hostname='+dns+'&ip='+ip));
  status:=copy(res,pos(':',res)+1,length(res));
  memo1.lines.add(getStatusFor(status));
end;


cheers:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peter2001Author Commented:
hi

sorry for the delayed reply as been away for the weekend

this is great thanks alot

works perfect

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.