Ronaldo Lanhellas Postado Julho 15, 2010 Denunciar Share Postado Julho 15, 2010 Constructor Create (AOwner: TComponent); override;gostaria de saber qual a função do AOwner, pos em certa parte do sistema o meu instrutor faz o seguinte: Create (AOwner);gostaria de saber também o que faz o "override"resumindo , o que este código faz Citar Link para o comentário Compartilhar em outros sites More sharing options...
0 Jhonas Postado Julho 15, 2010 Denunciar Share Postado Julho 15, 2010 No help do delphi explica:voce consegue entender o ingles ?? se não tente usar o tradutor da net.sempre que tiver duvida sobre um comando procure no help ( F1 ) ou pelo menos na biblia do delphi, tem tudo traduzido.A constructor is a special method that creates and initializes instance objects. The declaration of a constructor looks like a procedure declaration, but it begins with the word constructor. Examples:constructor Create;constructor Create(AOwner: TComponent);Constructors must use the default register calling convention. Although the declaration specifies no return value, when a constructor is called using a class reference, it returns a reference to the object it creates.A class can have more than one constructor, but most have only one. It is conventional to call the constructor Create.To create an object, call the constructor method in a class type. For example,MyObject := TMyClass.Create;This allocates storage for the new object on the heap, sets the values of all ordinal fields to zero, assigns nil to all pointer and class-type fields, and makes all string fields empty. Other actions specified in the constructor implementation are performed next; typically, objects are initialized based on values passed as parameters to the constructor. Finally, the constructor returns a reference to the newly allocated and initialized object. The type of the returned value is the same as the class type specified in the constructor call.If an exception is raised during execution of a constructor that was invoked on a class reference, the Destroy destructor is automatically called to destroy the unfinished object.When a constructor is called using an object reference (rather than a class reference), it does not create an object or return a value. Instead, the constructor operates on the specified object, executing only the statements in the constructor’s implementation. A constructor is typically invoked on an object reference in conjunction with the reserved word inherited to execute an inherited constructor.Here is an example of a class type and its constructor.type TShape = class(TGraphicControl) private FPen: TPen; FBrush: TBrush; procedure PenChanged(Sender: TObject); procedure BrushChanged(Sender: TObject); public constructor Create(Owner: TComponent); override; destructor Destroy; override; ... end;constructor TShape.Create(Owner: TComponent);begin inherited Create(Owner); // Initialize inherited parts Width := 65; // Change inherited properties Height := 65; FPen := TPen.Create; // Initialize new fields FPen.OnChange := PenChanged; FBrush := TBrush.Create; FBrush.OnChange := BrushChanged;end;The first action of a constructor is usually to call an inherited constructor to initialize the object’s inherited fields. The constructor then initializes the fields introduced in the descendant class. Because a constructor always clears the storage it allocates for a new object, all fields start with a value of zero (ordinal types), nil (pointer and class types), empty (string types), or Unassigned (variants). Hence there is no need to initialize fields in a constructor’s implementation except to nonzero or nonempty values.When invoked through a class-type identifier, a constructor declared as virtual is equivalent to a static constructor. When combined with class-reference types, however, virtual constructors allow polymorphic construction of objects—that is, construction of objects whose types aren’t known at compile time. (See Class references.)abraço Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
Ronaldo Lanhellas
Constructor Create (AOwner: TComponent); override;
gostaria de saber qual a função do AOwner, pos em certa parte do sistema o meu instrutor faz o seguinte: Create (AOwner);
gostaria de saber também o que faz o "override"
resumindo , o que este código faz
Link para o comentário
Compartilhar em outros sites
1 resposta a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.