Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using memo instead of messagebox

Posted on 2006-04-21
9
Medium Priority
?
600 Views
Last Modified: 2010-04-05

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;
0
Comment
Question by:peter2001
  • 3
  • 3
  • 3
9 Comments
 
LVL 2

Expert Comment

by:Mainiacfreakus
ID: 16513081
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
 
LVL 1

Author Comment

by:peter2001
ID: 16513962
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
 
LVL 2

Expert Comment

by:Mainiacfreakus
ID: 16513968
k, will test it...

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

Mainiacfreakus
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:Mainiacfreakus
ID: 16514083
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
 
LVL 1

Author Comment

by:peter2001
ID: 16514159
hi

thanks anyway  


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

unless anyone else has a better way


0
 
LVL 28

Expert Comment

by:2266180
ID: 16514661
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
 
LVL 28

Expert Comment

by:2266180
ID: 16514672
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
 
LVL 28

Accepted Solution

by:
2266180 earned 400 total points
ID: 16514690
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
 
LVL 1

Author Comment

by:peter2001
ID: 16519720
hi

sorry for the delayed reply as been away for the weekend

this is great thanks alot

works perfect

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 20 hours left to enroll

810 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