Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Delphi 7 LDAP via ADO / Field type

Posted on 2015-01-21
4
Medium Priority
?
601 Views
Last Modified: 2015-01-30
Hi all,
this is a question for legacy Delphi - I have to use D7 for this small project. I need to use some values from LDAP records, so I'm using a SQL query in a 'TBetterADODataSet' to retrieve my data. Later on, I want to display it in a grid and use some of those data in a report. But I don't have a plan how to use fields being obviously strings, but are inserted as TVariantField. This is the case for 'description', which holds the additional text information for a person in our AD.
When I'm adding that field to my SQL command and trying to insert it into my field list, it always inserts as 'TVariantField'. My grid can't use that field type.

Any ideas or workarounds? Sorry - I'm no longer doing my daily D7 programming for some years now, so there's some lack in experience :(

TIA
Michael
0
Comment
Question by:mkmko
  • 2
  • 2
4 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 40568891
If it contains String then Typecasting to string should do.

I suspect you can deal with similarly to when trying to show Memo fields in a DBGrid.

Can you test if "ShowMessage(urDataSet.FieldByName('description').AsString);", in a Button Click, gets you the data?
0
 

Author Comment

by:mkmko
ID: 40574614
Sorry for the delay... no, unfortunately this doesn't work. I have to translate the exception message because of my german Delphi installation: 'Error variant of type (array variant) couldn't be converted into type (string)'.

I checked that the ShowMessage is used and placed correctly by testing FieldByName('anotherStringField').AsString. This  will work.

Michael
0
 
LVL 24

Accepted Solution

by:
jimyX earned 2000 total points
ID: 40574701
Hi Michael,
That clears things out. If the problem is about Variant Array, then we should deal with it as so.

function GetVarArrayString(v: Variant): String;
var
  i: integer;
begin
  if VarIsArray(v) then
    begin
      Result:= '';
      for i:= VarArrayLowBound(v, 1) to VarArrayHighBound(v, 1) do
        begin
          Result:= Result+ VarToStr(v[i])+#13;
        end;
    end
  else showmessage('It is not an array.'); // Result:= VarToStr(v);
end;
...
// call it as follows:
ShowMessage(GetVarArrayString(urDataSet.FieldByName('description').Value));

Open in new window

0
 

Author Comment

by:mkmko
ID: 40579671
Yes, this works! Great!
Thanks a lot.

Michael
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Progress

916 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