Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

OPCDA subscription Cast Error in Delphi

More
15 Sep 2025 13:48 #14369 by wsalvin
Okay,
Thank you for your help.
I find the Issue,  the TLBs were not overrided.
Now it works, I will check if i still face memory leak.
And i will open another tread in case.
Regards
 
The following user(s) said Thank You: support

Please Log in or Create an account to join the conversation.

More
15 Sep 2025 09:52 #14368 by support
The I in angle brackets means "switch to italics" - this is BBCode, quite common in forums -  en.wikipedia.org/wiki/BBCode .

Enclose the entirety of your code in [code] instead.

I will rethink my answer and reply later.

 

Please Log in or Create an account to join the conversation.

More
15 Sep 2025 09:50 #14367 by wsalvin
Hello,
I suspect the TLBs was not overrided. let me do it again. I keep you informed.
Thank

Please Log in or Create an account to join the conversation.

More
15 Sep 2025 09:24 #14366 by wsalvin
again the "I" disappear. see previous screen shot.

Please Log in or Create an account to join the conversation.

More
15 Sep 2025 09:22 #14365 by wsalvin
Oups sorry.
I just checked my code.see screen shot.
in my code it's Arguments := ItemSubscriptionArguments;

I do not know why when i copy past the code  the '' disappear.
regards 
  • Please Log in or Create an account to join the conversation.

    More
    15 Sep 2025 09:05 - 15 Sep 2025 09:05 #14364 by support
    In your code, you create the Arguments as an array, that's true. But then, inside the loop, you overwrite with just one element:

     Arguments := ItemSubscriptionArguments;

    I do not see how this can work.

    Regards
     
    Last edit: 15 Sep 2025 09:05 by support.

    Please Log in or Create an account to join the conversation.

    More
    15 Sep 2025 08:56 #14363 by wsalvin
    Hello,
    My code is based on your exemple. the only diff is only that the number of requested Tag is a parameter and is include in a VCL app.
    I create an Array : Arguments := VarArrayCreate([0, NbTag - 1], varVariant); to pass to SubscribeMultipleItems.
    My code was working well on \OPC Labs QuickOPC 2020.2 except a memory leak.
    So I upgrade on 2025 in order to see if the memory leak is fixed. but i no more able to run my appli an i face the issue i sent you as screen shot on previous mail.
    To upgrade i installed the new 2025 release a regenerate TLB from SDK/Lib folder. 
    When I run the application I checked the DLL loaded by my app and now its the 2025 one.
    Any idea of what else i can do?
    Regards
     

    Please Log in or Create an account to join the conversation.

    More
    15 Sep 2025 08:29 #14362 by support
    Hello._EasyDAItemSubscriptionArguments is the right type for SubscribeMultipleItems. However, it has to be an *array* of them. Why don't you just base your code on the example provided for SubscribeMultipleItems? From opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Late...e%20to%20multiple%20items.html :
    Code:
    // This example shows how to subscribe to changes of multiple items and display the value of the item with each change. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . // OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP . // Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own // a commercial license in order to use Online Forums, and we reply to every post. type TSubscribeMultipleItems_ClientEventHandlers = class // Item changed event handler procedure OnItemChanged( ASender: TObject; sender: OleVariant; const eventArgs: _EasyDAItemChangedEventArgs); end; procedure TSubscribeMultipleItems_ClientEventHandlers.OnItemChanged( ASender: TObject; sender: OleVariant; const eventArgs: _EasyDAItemChangedEventArgs); begin if eventArgs.Succeeded then WriteLn(eventArgs.Arguments.ItemDescriptor.ItemId, ': ', eventArgs.Vtq.ToString) else WriteLn(eventArgs.Arguments.ItemDescriptor.ItemId, ' *** Failure: ', eventArgs.ErrorMessageBrief); end; class procedure SubscribeMultipleItems.Main; var Arguments: OleVariant; Client: TEasyDAClient; ClientEventHandlers: TSubscribeMultipleItems_ClientEventHandlers; HandleArray: OleVariant; ItemSubscriptionArguments1: _EasyDAItemSubscriptionArguments; ItemSubscriptionArguments2: _EasyDAItemSubscriptionArguments; ItemSubscriptionArguments3: _EasyDAItemSubscriptionArguments; ItemSubscriptionArguments4: _EasyDAItemSubscriptionArguments; begin ItemSubscriptionArguments1 := CoEasyDAItemSubscriptionArguments.Create; ItemSubscriptionArguments1.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2'; ItemSubscriptionArguments1.ItemDescriptor.ItemID := 'Simulation.Random'; ItemSubscriptionArguments1.GroupParameters.RequestedUpdateRate := 1000; ItemSubscriptionArguments2 := CoEasyDAItemSubscriptionArguments.Create; ItemSubscriptionArguments2.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2'; ItemSubscriptionArguments2.ItemDescriptor.ItemID := 'Trends.Ramp (1 min)'; ItemSubscriptionArguments2.GroupParameters.RequestedUpdateRate := 1000; ItemSubscriptionArguments3 := CoEasyDAItemSubscriptionArguments.Create; ItemSubscriptionArguments3.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2'; ItemSubscriptionArguments3.ItemDescriptor.ItemID := 'Trends.Sine (1 min)'; ItemSubscriptionArguments3.GroupParameters.RequestedUpdateRate := 1000; ItemSubscriptionArguments4 := CoEasyDAItemSubscriptionArguments.Create; ItemSubscriptionArguments4.ServerDescriptor.ServerClass := 'OPCLabs.KitServer.2'; ItemSubscriptionArguments4.ItemDescriptor.ItemID := 'Simulation.Register_I4'; ItemSubscriptionArguments4.GroupParameters.RequestedUpdateRate := 1000; Arguments := VarArrayCreate([0, 3], varVariant); Arguments[0] := ItemSubscriptionArguments1; Arguments[1] := ItemSubscriptionArguments2; Arguments[2] := ItemSubscriptionArguments3; Arguments[3] := ItemSubscriptionArguments4; // Instantiate the client object and hook events Client := TEasyDAClient.Create(nil); ClientEventHandlers := TSubscribeMultipleItems_ClientEventHandlers.Create; Client.OnItemChanged := ClientEventHandlers.OnItemChanged; TVarData(HandleArray).VType := varArray or varVariant; TVarData(HandleArray).VArray := PVarArray( Client.SubscribeMultipleItems(Arguments)); WriteLn('Processing item changed events for 1 minute...'); PumpSleep(60*1000); WriteLn('Unsubscribing...'); Client.UnsubscribeAllItems; WriteLn('Waiting for 5 seconds...'); PumpSleep(5*1000); WriteLn('Finished.'); VarClear(HandleArray); VarClear(Arguments); FreeAndNil(Client); FreeAndNil(ClientEventHandlers); end;

    Please Log in or Create an account to join the conversation.

    More
    15 Sep 2025 07:43 #14361 by wsalvin
    hello i'm doing the following test In Delphi 12 with the last release QuickOPC (2025.1) I just downloaded.

    procedure TForm3.btnAddOpcdaClick(Sender: TObject);
    var
      Arguments: OleVariant;
      ItemSubscriptionArguments: _EasyDAItemSubscriptionArguments;
    //  ItemSubscriptionArguments: _DAReadItemArguments;
    //  ItemSubscriptionArguments: _DAItemGroupArguments;
      HandleArray: OleVariant;
      I: Integer;
    begin
      // exemple in kb.opclabs.com/Reference_counting_in_Delphi
      //https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/User%27s%20Guide%20and%20Reference-OPC%20Studio/Examples%20-%20OPC%20Data%20Access%20-%20Subscribe%20to%20multiple%20items.html
    //  CoInitialize(nil);
      ClientEventHandlers := TClientEventHandlers.Create;
      ClientOPCDA := TEasyDAClient.Create(nil);
      ClientOPCDA.OnItemChanged := ClientEventHandlers.OnDataChangeNotification;
      Arguments := VarArrayCreate([0, NbTag - 1], varVariant);

      //init tag requested
      for I := 0 to NbTag - 1 do
      begin
        ItemSubscriptionArguments := CoEasyDAItemSubscriptionArguments.Create;
    //    ItemSubscriptionArguments := CoDAReadItemArguments.Create;
    //    ItemSubscriptionArguments := CoDAItemGroupArguments.Create;
          //Nom du PC
        ItemSubscriptionArguments.ServerDescriptor.MachineName := 'localhost';
          //Nom du serveur OPC
        ItemSubscriptionArguments.ServerDescriptor.ServerClass := 'Kepware.KEPServerEX.V6';
          //Nom du tag OPC
        ItemSubscriptionArguments.ItemDescriptor.ItemID := 'Simulation Examples.Functions.Ramp' + (I + 1).ToString;
          //Delai de rafraichissement
        ItemSubscriptionArguments.GroupParameters.RequestedUpdateRate := 1000;
        Arguments := ItemSubscriptionArguments;
      end;
      ClientOPCDA.SubscribeMultipleItems(Arguments);


      btnAddOpcda.Enabled := False;
      btnRemOpcda.Enabled := True;
      CodeSite.send('OPCDA Added');
    end;

    I face the following Error.
    Impossible d'effectuer un cast d'un objet de type 'OpcLabs.EasyOPC.DataAccess.OperationModel.EasyDAItemSubscriptionArguments en type OpcLabs.EasyOPC.DataAccess.OperationModel.DaReadItemArguments.

     


    Is _EasyDAItemSubscriptionArguments the right type to use for the array to pass to SubscribeMultipleItems?
    Regards
  • Please Log in or Create an account to join the conversation.

    Moderators: supportvaclav.zaloudek
    Time to create page: 2.753 seconds