Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 651
  • Last Modified:

Delphi 7 LDAP via ADO / Field type

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
mkmko
Asked:
mkmko
  • 2
  • 2
1 Solution
 
jimyXCommented:
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
 
mkmkoAuthor Commented:
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
 
jimyXCommented:
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
 
mkmkoAuthor Commented:
Yes, this works! Great!
Thanks a lot.

Michael
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now