Toon posts:

[BC6] Afgeleide van een TStringGrid

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik wilde een afgeleide maken van TStringGrid die een rooster op het scherm zet. Ik dacht dat doe ik hetzelfde als met andere dingen, maar op de een of andere manier kan hij de defaultconstructor niet vinden.

Dit is mijn code:

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//---------------------------------------------------------------------------

#ifndef roosterStringGridH
#define roosterStringGridH
//---------------------------------------------------------------------------
#endif

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <ExtCtrls.hpp>
#include <DBGrids.hpp>
#include <Grids.hpp>
#include <ComCtrls.hpp>
#include <ActnCtrls.hpp>
#include <ActnMan.hpp>
#include <ActnMenus.hpp>
#include <ToolWin.hpp>
#include <ActnList.hpp>
#include <Grids.hpp>

class RoosterStringGrid : public TStringGrid
{
TStringGrid *Rooster;
public:


        RoosterStringGrid(TWinControl *Sender);
        RoosterStringGrid();
};

RoosterStringGrid::RoosterStringGrid(TWinControl *Sender){
        Rooster = new TStringGrid(Sender);
        Rooster->Parent=Sender;

        Rooster->ColCount=4;
        Rooster->RowCount=10;
        Rooster->Color=clWhite;
        Rooster->Left = 48;
        Rooster->Top = 96;
        Rooster->Color = clWhite;
        Rooster->DefaultRowHeight = 20;
        Rooster->DefaultColWidth=50;

        Rooster->Height = (Rooster->RowCount)*(Rooster->DefaultRowHeight+Rooster->GridLineWidth)+4;
        Rooster->ScrollBars=ssNone;
        Rooster->FixedColor = 16768477;
        Rooster->Font->Charset = DEFAULT_CHARSET;
        Rooster->Font->Color = clBlack;
        Rooster->Font->Height = -11;
        Rooster->Font->Name = "MS Sans Serif";
        Rooster->Width=Rooster->ColCount*Rooster->DefaultColWidth+7;
        Rooster->ParentBiDiMode = False;
        Rooster->ParentFont = False;
        Rooster->TabOrder = 5;
        Rooster->Visible=true;

        for(int i=1;i<Rooster->RowCount;i++){
                Rooster->Cells[0][i]="dag" + IntToStr(i);
        }

        Rooster->Cells[1][0]="Docent";
        Rooster->Cells[2][0]="Lokaal";
        Rooster->Cells[3][0]="Vak";
}


Ik wil eigenlijk ook dat er geen defaultdrawing wordt gedaan. Ik weet dat je dan die var. op false moet zetten(duhh), maar dan moet je een of andere vage functie weer meegeven aan onDrawCell, en daar gaat het ook mis. Ik heb al wel een functie gemaakt, voor als ik hem @ designtime er neer zet, maar ik wel juist een object krijgen dat ik @ runtime op het scherm kan zetten.

P.S. Ik include superveel en waarschijnlijk te veel, maar dat boeit me niet zo.

  • LordLarry
  • Registratie: Juli 2001
  • Niet online

LordLarry

Aut disce aut discede

Erm...je maakt een StringGrid in je afgeleide?! Dat is een wel heel vreemde manier of heb je daar een goede rede voor?

We adore chaos because we like to restore order - M.C. Escher


  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

LordLarry schreef op 15 april 2003 @ 22:21:
Erm...je maakt een StringGrid in je afgeleide?! Dat is een wel heel vreemde manier of heb je daar een goede rede voor?
Telt dat verhaal met die klok en die klepel als een goede reden? ;)

Nofi, maar gang-ster je hebt weinig kaas gegeten van de materie. Als je een class inherit (ook wel bekend als 'extenden' oftewel uitbreiden) heeft de afgeleide class alle functionaliteit van de base class. Wat je wilt is dus als volgt:
C++:
1
2
3
4
5
6
7
8
9
10
11
class RoosterStringGrid : public TStringGrid 
{ 
public: 
        RoosterStringGrid(TComponent *Owner);   // Geen sender, niets van doen met events
}; 

RoosterStringGrid::RoosterStringGrid(TComponent *Owner )
:TStringGrid(Owner)       // DEZE REGEL WAS JE VERGETEN
{
// Set custom properties 
}

En nu kun je alle virtual methods uit de base classes overloaden om je eigen functionaliteit binnen te schuiven.

Ik raad je aan een paar tutorials/boeken op te zoeken, dit gaat heel snel heel frustrerend voor je worden met jouw achtergrondkennis....

* curry684 is also referring to this post...

[ Voor 7% gewijzigd door curry684 op 16-04-2003 01:40 ]

Professionele website nodig?


Verwijderd

Topicstarter
Je code klopte niet helemaal, tenminste niet voor BC6. Er moest nog __fastcall voor. :)
Maar evengoed bedankt.

  • curry684
  • Registratie: Juni 2000
  • Laatst online: 13-08 16:46

curry684

left part of the evil twins

Verwijderd schreef op 17 April 2003 @ 21:19:
Je code klopte niet helemaal, tenminste niet voor BC6. Er moest nog __fastcall voor. :)
Maar evengoed bedankt.
Ik heb jouw code gewoon geedit totdat ie klopte, jouw fout dus. Code van mij op GoT is zelden gecompileerd, meestal gebouwd in Notepad. :z

Professionele website nodig?