Hi all

I am having a small problem with the following bit of code in D4 and it is
still there in D6 but has created another problem, but this could be a small
D6 bug.

procedure TForm1.Button1Click(Sender: TObject)
var  Buffer:  String;
     name : String[10];
     BuffSize : DWORD;
begin
    Buffsize := 128;
    SetLength(Buffer, Buffsize);
    GetUserName(PChar(Buffer), Buffsize);
    name := Trim(buffer);
    Table1.Filter := 'USERID = ' + chr(39)+ TRIM(name) + chr(39);
    Table1.Filtered := true;
    If not Table1.Active then
       Table1.Open;
end;

Under D4 I am trying to filter all the records in a grid who have the USERID
in the table equal the current user.

The problem is that the first time to code is executed it comes up with an
'Unterminated string constant' error which is ridiculous as
the user is terminated with an '. But it you look at what Table1.filter has
got in it in the watch window is has:
        
        Table1.Filter: 'USERID = 'xxx'

This is showing unbalanced quotes. The first is quote is shown in window
because the filter property in a string.

If the code is executed again with then the watch window shows

        Table1.Filter: 'USERID = 'xxx''

The quotes are not balanced and it works.

If I type USERID = 'xxx' in the property under the Obejct Inspector is work
fine everytime. It's only when trying to code this setting that it falls
over.

Why do you think this is happening? I can't see that is the code as it works
the second time round.

Under D6 pro though the string returned from looking up of the users id has
extra characters in it in the Buffer field, the first time through. This
time it shows

        Table1.Filter: 'USERID = 'xxx'#0'J'#0'1/46''

and fails but second time through again and it works fine and has

        Table1.Filter: 'USERID = 'xxx''

These extra control characters must be something special D6 in now finding
the first time which D4 doesn't.

Should there be some other variable I should be initializing first which
obviously has been set an new value after the code has been execute once?

I have tryed putting and extra numeric condition in such as

        Table1.Filter := 'USERID = ' + chr(39)+ TRIM(name) + chr(39) + ' AND
QTY > 0'

I though this might trick it into putting the second quote in properly but
it didn't

Thanks for any assistance.
Eion McIntosh
PPCS Ltd


---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to