Tech Notes
Tech Notes |
Code example: lookup on primary key and display record
In WebHub, there are many ways to position the database cursor on a particular record. The technique described here is a do-it-yourself approach that works in all versions of WebHub.
In this example, the surfer is asked to enter two pieces of information, their social security number ("SSN") (which we presume to be unique) and their bank loan number. The intended result is additional information about their account from the database.
Typical HTML that would go in the page definitions
<whpage pageid="search"> <!--The "result" in the next line refers to the following page name--> <form method="post" action="(~ACTIONR|result~)"> <!--The "loan_number" in the next line refers to the db field--> Your Loan Number: <input type="text" name="loan_number" /><br/> Your Account Number: <input type="text" name="account" /><br> <input type="submit" /> </form> </whpage> <whpage pageid="result"> (~requires|loan_number|pgError~) <h2>result of search</h2> (~evLocateRecord=% (~field|webdatasource1|last_payment~) (~field|webdatasource1|date_received~) (~field|webdatasource1|current_interest~) </whpage> <whpage pageid="pgError"> <h2>You must enter your bank loan number!</h2> </whpage>
Delphi Code:
procedure TForm1.WebDemoAppEventMacro(Sender: TwhRespondingApp; const aMacro,
aParams, aID: string);
var
loanNum: String;
begin
{ 1. assume that only one event macro is used, i.e. aMacro = evLocateRecord
2. assume that Table1 is the dataset pointed to by webdatasource1
}
with table1 do
begin
if NOT Active then
Open;
loanNum := pWebApp.StringVar['Loan_Number'];
// HTML validates the loan number as a required field
if NOT FindKey([loanNum]) then
begin
//findkey only works on primary key
raise Exception.Create('Invalid loan number: '+loanNum); // A15 *
end;
if FieldByName('account').asString <> pWebApp.StringVar['account'] then
raise Exception.Create('Loan# does not match your account number');
end;
end;
Copyright © 1995-2010 HREF Tools Corp. All Rights Reserved Worldwide. 05-Aug-2007.
Running DynHelp.exe v1.2.0.6 on WebHub-v2.128 built by D15
Calc time: 203 ms
Running DynHelp.exe v1.2.0.6 on WebHub-v2.128 built by D15
Calc time: 203 ms

