Changes

Jump to: navigation, search

OOP344 Assignment Two

667 bytes added, 11:42, 19 October 2009
IO_Label
Inherit a new class called IO_Label from IO_Field to Display a text message on IO_Form. In addition to the attributes of its parent IO_Field, IO_Label has a private integer attribute called _len. _len is used to hold the length of Field in which the text is to be displayed.
IO_Label could hold its data dynamically or simply point to an external one. Because of this IO_Label also has a boolean attribute called _dynamic that will hold the type of data within; being dynamic memory (value true), or external memory (value false)
'''IO_Label''' can be created in two ways:;
'''1-'''
<big><pre>
IO_Label(int row, int col, int len);
This constructor will create an empty (blank) IO_Label with capacity of len characters.
In this case '''row''' and '''col''' are passed to the parent for initialisation and '''_len''' (the atterbute) is set to the incoming argument '''len''';.
Then IO_Field::_data will be set to the address of a newly allocated memory to the size of '''_len + 1 ''' bytes which also will be set to an empty string.
''Note that '''data''' is a void pointer; to use it here, you must cast it to a character pointer!''<br /> 
'''_dynamic''' attribute is set to true in this case.
'''2-'''
<big><pre>
IO_Label(char* str, int row, int col, int len = -1);
'''_dynamic''' attribute is set to false in this case, since the data of the class is external.
====Public Methods====
<big><pre>
 
void Display(void);
 
</pre></big>
void Set(const void* str);
</pre></big>
 
'''Set()''' will copy the content of '''str''' into '''IO_Field::_data''' up to '''_len''' characters, if '''_len''' is not negative.
<big><pre>
 
bool IO_Label::Editable(void)const;
 
</pre></big>
 
'''Editalbe()''' returns false!.
 
<bid><pre>
 
int Edit(IO_Form* Owner=(IO_Form*)0);
 
</pre></big>
 
'''Edit()''', Calls '''Display()''' and returns '''0'''. This method ignores the '''Owner''', IO_Form pointer.
 
<bid><pre>
 
~IO_Label(void);
 
</pre></big>
 
The destructor, delete[]s the '''_data''' only if '''_dynamic''' is true.
 
<bid><pre>
 
IO_Label &operator=(const char* str);
 
</pre></big>
 
'''operator=()''', Calls '''Set()''' and returns itself.
===IO_Edit===

Navigation menu