TDBLookup.FetchLookupData proposal fix lazarus / 16-Databases ---------------------------------------------------------------------- swierzbicki · 2013-11-08 10:00 Hello, There is a problem with the TBDLookupCombobox (DBLookup.inc) component that leads to a SIGSEGV exception. It happens when the assigned Dataset isn't active. Here is a call stack, error happens at 00592E27 ff9334010000           call   *0x134(%ebx) Code: [Select]DB_TFIELD_$__GETDISPLAYTEXT$$ANSISTRING 00592DE0 55                       push   %ebp 00592DE1 89e5                     mov    %esp,%ebp 00592DE3 83ec0c                   sub    $0xc,%esp 00592DE6 895df4                   mov    %ebx,-0xc(%ebp) 00592DE9 8975f8                   mov    %esi,-0x8(%ebp) 00592DEC 89c3                     mov    %eax,%ebx 00592DEE 8955fc                   mov    %edx,-0x4(%ebp) 00592DF1 8b45fc                   mov    -0x4(%ebp),%eax 00592DF4 ba00000000               mov    $0x0,%edx 00592DF9 e8b24fe7ff               call   0x407db0 00592DFE 83bba000000000           cmpl   $0x0,0xa0(%ebx) 00592E05 7417                     je     0x592e1e 00592E07 6a01                     push   $0x1 00592E09 8b83a4000000             mov    0xa4(%ebx),%eax 00592E0F 8b4dfc                   mov    -0x4(%ebp),%ecx 00592E12 89da                     mov    %ebx,%edx 00592E14 8bb3a0000000             mov    0xa0(%ebx),%esi 00592E1A ffd6                     call   *%esi 00592E1C eb0f                     jmp    0x592e2d 00592E1E 8b55fc                   mov    -0x4(%ebp),%edx 00592E21 89d8                     mov    %ebx,%eax 00592E23 b101                     mov    $0x1,%cl 00592E25 8b1b                     mov    (%ebx),%ebx 00592E27 ff9334010000             call   *0x134(%ebx) 00592E2D 8b5df4                   mov    -0xc(%ebp),%ebx 00592E30 8b75f8                   mov    -0x8(%ebp),%esi 00592E33 c9                       leave  00592E34 c3                       ret    00592E35 0000                     add    %al,(%eax) 00592E37 0000                     add    %al,(%eax) 00592E39 0000                     add    %al,(%eax) 00592E3B 0000                     add    %al,(%eax) 00592E3D 0000                     add    %al,(%eax) 00592E3F 00                       add    %al,0x5c8908ec(%ebx) It happens in the TDBLookup.FetchLookupData method, where items are added : s := FListField.DisplayText;  I don't know if it is the correct way but I solved it by exiting the method if the assigned dataset isn't active : procedure TDBLookup.FetchLookupData; var   s: String;   i: Integer; begin   if not Assigned(FControlItems) then     Exit;   FControlItems.Clear;   if not (Assigned(FListLink.DataSet) and Assigned(FListField)) then     Exit;   if not FListLink.DataSet.Active then     exit;   LinkGetBookMark;   try     //needed to handle sqldb.TSQLQuery that does not has a reliable recordcount after Open     FListLink.DataSet.Last;     FListLink.DataSet.First;     SetLength(FListKeys, FListLink.DataSet.RecordCount);     i := 0;     while not FListLink.DataSet.EOF do     begin       s := FListField.DisplayText;       FListKeys := FListLink.DataSet.FieldValues[FKeyFieldNames];       Inc(i);       FControlItems.Add(s);       FListLink.DataSet.Next;     end;   finally     LinkGotoBookMark;   end; end; BR Stéphane ---------------------------------------------------------------------- taazz · 2013-11-08 10:25 Actually my choice would be to either activate the dataset or raise an exception. In your case and since you try to avoid seeing an error I would suggest to activate the dataset ee Code: [Select] if not FListLink.DataSet.Active then FListLink.DataSet.Active := true; // or FListLink.DataSet.open; ---------------------------------------------------------------------- swierzbicki · 2013-11-08 11:10 @taaz : I really think that Dataset should be close. I've cases when my forms are displayed and lookup dataset are not opened because they depends settings that users has to enter. If I remember, default Delphi behaviour is the same : if the dataset is close the Lookup component doesn't display anything. ---------------------------------------------------------------------- taazz · 2013-11-08 13:09 I think that this is something for the application to decide and not the framework, it is better to get a message than to scratch your head why there are no rows in the lookup especially if you think that during developing the lookup data might be empty and only get data from the customer so to see an empty lookup might be expected with the dataset open but a closed dataset is always a human error at least as far as my experience goes. ---------------------------------------------------------------------- swierzbicki · 2013-11-08 13:42 I think you misunderstood me. Take this example: - Create a new form - Add one or more TSQLQuery, enter the SQL property and then create persistent fields - Make sure the TSQLQueries beings disabled - Add more TDBLookupComboBox / TDBLookup Start your application and you will get a SIGSEG error. This is clearly a bug. TLookup object attempts to load items from a disabled dataset : this should be avoided ! This is not desirable that the framework change the dataset state if the latter is disabled. If the listesource dataset is empty than the TDBlookup component should retrieve nothing then an empty list ! I've modified the source code to take this consideration. I also agree that the developer decides whether to activate or not the TDataset state. Ps : error are also catched by the IDE since this behaviour is reproduced at design time. ---------------------------------------------------------------------- taazz · 2013-11-08 14:07 Lets get the facts of the case 1) I'm not willing to do the work so what ever I say you can ignore it. 2) what you describe it is a bug and it should be addressed as soon as possible but before going any farther please check that the bug still exists on 1.2RC1. 3) The bug should be address one step before FetchLookupData method checking something along the lines of if (csLoading in componentsState) and (not lookupList.active) then skipDataLoading. That will leave open the option for different types of handling based on various conditions. 4) I do remember that this bug was discussed in this forum in the past but I do not remember how it was addressed. If you are using lazarus 1.0.10 as your signature states then I would try the 1.0.12 to see if it already solved there or directly the 1.2RC1. if the bug still exists then make a bug report at the bug tracker so it can be addressed for the 1.2 release with your patch attached. You can find the Bug tracker link on the menu at the left of the screen. ---------------------------------------------------------------------- swierzbicki · 2013-11-08 14:56 That's OK taazz, I didn't want to upset you ! FWIW I've updated my signature since I'm working with Laz. 1.0.12. I'll test my project under Laz 1.2RC1 : I will open a ticket If the bug is still present . Thanks ---------------------------------------------------------------------- taazz · 2013-11-08 15:07 No worries you didn't, I just do not want to come off as the guy that tells you what to do by expressing an opinion and nothing more. Since I haven't looked at the source to know what I'm talking about everything is just an educated guess and a generic guideline I use in my frameworks. ---------------------------------------------------------------------- LuizAmérico · 2013-11-24 23:28 Version 1.2 already has the fix:  // Prevent SIGSEGV if ListLinkDataset is closed   if not ListLinkDataset.Active then     Exit;