[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Delphi COM Object

Posted on 2005-05-03
9
Medium Priority
?
479 Views
Last Modified: 2010-04-05
I've written an ActiveX DLL/Com object with various calls.  One of the calls is a simple GetVersion which returns a version no.  This works in Delphi but when I test it in Access for example (I don't have VB) my whole access crashes.  The other functions work fine even when returning integers.


const
  Version = '1.20';
::
::
::
function TMyObject.GetVersion: WideString;
begin
  Result := Version;
end;

It's definition in the com class is :
   
   function GetVersion: WideString; stdcall;

Inside Access:
::
Set ao = CreateObject("MyClass.MyObject")
MsgBox ao.GetVersion

Please help.  This should be very easy, I just don't know what I'm missing.



0
Comment
Question by:shokotah
  • 4
  • 3
  • 2
9 Comments
 
LVL 6

Expert Comment

by:pritaeas
ID: 13918474
any other widestring function failing? Did you try other strings?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 13918550
Won't it be a memory allocation issue?.. Don't you have to allocate space for a BSTR and return that, preventing Delphi tidying the WideString memory for you?

Try defining the function as returning a BSTR instead, then do something like:

x : WideString;
x := Version;
return X.Detach();

in the implementation function.


(Sorry - don't have Delphi set up at the minute)

0
 

Author Comment

by:shokotah
ID: 13918604
If I return the result as a param it's fine.  It is just the functions that return strings as themselves that give problems.  I've tried LPSTR (PCHAR), LPWSTR (PWIDECHAR), Variant (OleVariant) and obviously BSTR (WideString) bu no success.  On LPSTR and LPWSTR Access tells me that it does not support the data type.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Accepted Solution

by:
pritaeas earned 150 total points
ID: 13918628
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 13918658
Returning as a param probably means the caller is allocating the memory etc...

Have you tried my suggestion using Detach() ?
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 13918677
Forgot this one: (don't know what version you are using)

Quote: You can not assign strings to PChar or PWideChar in Delphi 2005. .NET strings are not modifiable, and you can not take the address of a character in the string. Therefore, PChar and PWideChar are not assignment compatible with String. You need to copy the string data to a local array variable. PChar and PWideChar will work with local array variables.
0
 

Author Comment

by:shokotah
ID: 13918760
I'm using Delphi 7.  The Detach() method is not available to me.
0
 

Author Comment

by:shokotah
ID: 13942894
Problem solved ... somewhat.  Created a property with a function behind it and it seems to work.  Thanks for all the input.
0
 

Author Comment

by:shokotah
ID: 13942897
Moderator can you please close this question and refund the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 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