Delphi 7 LDAP via ADO / Field type

Posted on 2015-01-21
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 :(

Question by:mkmko
  • 2
  • 2
LVL 24

Expert Comment

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?

Author Comment

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.

LVL 24

Accepted Solution

jimyX earned 500 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;
  i: integer;
  if VarIsArray(v) then
      Result:= '';
      for i:= VarArrayLowBound(v, 1) to VarArrayHighBound(v, 1) do
          Result:= Result+ VarToStr(v[i])+#13;
  else showmessage('It is not an array.'); // Result:= VarToStr(v);
// call it as follows:

Open in new window


Author Comment

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


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 53
topping3 challenge 14 52
index Out OF Range Exception error 4 33
Path to Python 9 48
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now