So I have a string grid with columns. But each column can be deleted and if a column is deleted indexes are rearranged. I can use the value of my index before deletion, but when it comes to delete several columns the indexes aren't the same at all. For example if i delete the column at index 1 and 2, the one that was at index 3 get a new index, index 1.
So what I want to do is to add new methods to my columns where i will set and get the real index, as it was never deleted. I have found a tutorial on how to add new methods to delphi classes and this is how it looks:
unit columnInterceptor
interface
uses stdCtrls, sysUtils, Classes, dialogs, grids;
type
TStrings = class(Classes.TStrings)
private
public
procedure hello;
end;
implementation
procedure TStrings.Hello;
begin
ShowMessage('hello');
end;
end.
This works if i use it to add methods on a StringGrid. But i want to use this on a Column of a stringGrid. I've seen that some methods are coming from the class TStrings or TObject, and i tried them both but the procedure hello doesn't show.
EDIT
Using class helper i managed to have access to my own method and after changing this is how it looks:
unit columnInterceptor
interface
uses stdCtrls, sysUtils, Classes, dialogs, grids;
type
colIntercept= class helper for TStrings
public
procedure setValue(val: integer);
function getValue: integer;
end;
implementation
var
value : integer;
procedure colIntercept.setValue(val: integer);
begin
value := integer;;
end;
function colIntercept.getValue: integer;
begin
Result := value;
end;
end.
Thing is that if i add a private statement i can't use my methods anymore which are declared in public statement. And when i set a value it's actually the same for all columns. This is how i uses this class:
//somewhere in the unit where create all the columns
grid.Cols[aCol].setValue(aCol);
//somewhere in the unit
grid.Cols[aCol].getValue
And then all the value for any column is always the same. When i'm setting my values they are different each time. But getting them, returns me always the last value i inserted using setValue method.