Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:58:12+00:00 2026-06-12T03:58:12+00:00

The question arises from the need to reuse a code for different types of

  • 0

The question arises from the need to reuse a code for different types of objects.

  • Scenario:

Drag and Drop in listboxes either from a different listbox or same.
above question arises, when i try to implement drag and drop in same control.
the user can rearrange items in a listbox by dragging them up or down.
I have written the logic, it works.
The problem is, in my app, i have used different kind of listboxes as per requirement.
So their type gets changed. in order to use the same code for drag and drop,
when the source and sender is same, i typecasted different list-boxes to the common ancestor TCustomListBox
and then sent that to the function which performs the moving of items.
The function swaps the items from the items collection to their new positions.

  • Now particular scenario:

    i have used a checklistbox which has a checkbox associated with each item.
    It so happens, that with each item, there is an object of checkstate associated.
    Now in the function, for moving items, i use a tstringlist for temporary storing the items
    and their objects and then delete them from the control and then reinsert them in the control.
    but in case of this checklistbox, when i delete an item, the item gets deleted,
    but its corresponding checkstate object remains and it gets associated to the next item,
    which is not desired.
    so right now i am using an int variable as a mode indicator for normal,
    and special dragdrop.
    when it is special, as in case of checklistbox, i typecast it to tchecklist and
    then access its delete method which removes item alongwith its checkstate.

    So instead of using an int as a mode, i was wondering,
    whether i can use a class reference of the base class of all listboxes and
    then how can i access the properties of a particular listbox type, if the need arises.
    the above solution, is not optimum, thats why, i need a more generic and proper way.
    See if you can help. thanks. and thanks for the advise, i do care for this community, i am not used to editing features. sorry.

i am using delphi 6.
The declaration for the function is as follows :-
DragDropItemsInListBox(p_HostIndex : Integer; p_HostListBox : TCustomListBox;
p_Mode:Integer);

call:-
the hostindex is the drop site index, hostlistbox is the control on which the item will be dropped,
in this case, the source control and destination control is same,
and mode indicates the way of deleting.
DragDropItemsInListBox(3,TCustomListBox(Source), 1);

if the mode is 0 then i delete items normally as in:-
p_HostListBox.items.delete(i);

if it is 1, which indicates special processing,
in this case as i know what to do, therefore i use,

if p_Mode = 1 then
(p_HostListBox as TRzCheckList).items.delete(i);

this removes the item alongwith the checkstate object.
but i dont wanna rely on this int based differentiation.
can i use metaclasses and if i normally call items.delete,
then will it apply to that specific type?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:58:13+00:00Added an answer on June 12, 2026 at 3:58 am

    therefore i use, if p_Mode = 1 then (p_HostListBox as
    TRzCheckList).items.delete(i);

    this removes the item alongwith the checkstate object. but i dont
    wanna rely on this int based differentiation. can i use metaclasses
    and if i normally call items.delete, then will it apply to that
    specific type?

    You can not use metaclass variable – the metaclass pointer is the same for all the objects of the type. If Delphi allowed that – would have no way to know which of checklists to delete from.

    However using int is poor solution indeed.

    if p_HostListBox is TRzCheckList 
       then TRzCheckList(p_HostListBox).items.delete(i); 
    

    Sidenote: in Component Pascal there would be even more sugar: IS
    implies AS there: if p_HostListBox is TRzCheckList then
    p_HostListBox.items.delete(i);

    Probably yet better approach to read help about RzChkLst.TRzCheckList.Items – that is property of TStrings type.

    Modify the declaration

    procedure DragDropItemsInListBox(p_HostIndex : Integer; p_HostListBox : TCustomListBox; p_Items : TStrings);
    

    Call it like DragDropItemsInListBox(0, RzCheckList1, RzCheckList1.Items);

    And in procedure do

    p_Items.Delete(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to translate some of our UI to English, and the question arises:
This Question arises from a Q&A here I have some doubts that i think
This question arises from this question . One saying is that if a language
The question arises from the reply . How can I change the storing from
My question arises from the post Plain English Explanation of Big O . I
Question from Object-Oriented JavaScript book: Imagine Array() doesn't exist and the array literal notation
Question is already been asked in title. Here is a code: (function($){ var filter
Here's the question first: Is this possible? I'm taking my inspiration from Joe Wrobel's
This question arises out of a combination of this being my first time working
From http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/ , code such as class Base { public: virtual void function1() {};

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.