2

I'd like create a dll to import data from a file (different format, for example csv, txt, xls, ...). My idea is this: the dll load the data with her "engine" then send this data to my application so my application can show them inside a grid.

This is my second DLL so I have some problems/questions.

I think my DLL should send the data to a TDataset on my application but how can I call a DLL with a TDataset as argument?

Any suggestions? What is the easiest way to accomplish what I have in mind? (if possible)

Martin
  • 1,065
  • 1
  • 17
  • 36

2 Answers2

2

If you are the creator of those DLL's, then consider to use packages instead of DLL. This will avoid the problems, like dublicate Delphi RTTI, plain DLL API. Then you will need to properly split classes between packages, load packages statically or dynamically, get reference to a class implementing import engine, and call the corresponding method with a dataset reference as a parameter value.

oodesigner
  • 1,007
  • 6
  • 8
  • This is indeed recommended approcah in case the formats are all known. In my similar project I used dynamically loaded DLLs. So is some user needed to import or export his data format then I could just write new DLL, send it to him and he would configure the program to load this DLL instead. – Riho Sep 22 '11 at 08:25
0

Easier way for you would be to store the data directly into database in DLL. And after import you just refresh your TDataset.

BTW, you don't "call DLL", you call some method that is public in DLL and there you can use arguments as in normal methods.

EDIT: For more generic DLLs that don't require data components just send data in struct

 TMyData
 { int ID;
   String Value;
 };

int MyDataImport(TMyData & data)
{
...
}
Riho
  • 4,523
  • 3
  • 33
  • 48
  • Yes, this is a way and I think I will do it if I will not found any other solution. However I'd like send extract data from my application and dot from DLL. In this way in fact my DLL will be a generic DLL and I will use in other projects (that use different database engine). Yes, I can call a function of DLL not the DLL :) sorry. – Martin Sep 22 '11 at 07:48
  • I don't think you can use this DLL as generic one for different projects, unless they all use the same data. – Riho Sep 22 '11 at 07:52
  • OK, but in my case I have my data, I should send a grid (with rows and columns)...please only delphi code (if possible), thanks in any case – Martin Sep 22 '11 at 08:05
  • 1
    My advice: do not use DLLs if you have the opportunity to use packages. Packages are in fact DLLs, but with a lot of extra "knowledge" about Delphi's data types, so they do not require any considerations as to what can be passed in and out, or how. It is like using units. Passing class instances between application and DLL is generally a bad idea. – Rudy Velthuis Sep 22 '11 at 08:46