[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

qoy: unit with empty interface section

Posted on 2004-03-25
27
Medium Priority
?
458 Views
Last Modified: 2010-04-05
Question of the Year

Can a unit with empty interface section be useful and how?

unit Strange;

interface

implementation


BTW I do know the answer. This is for education purposes (and the fun :)
0
Comment
Question by:robert_marquardt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 4
  • +5
27 Comments
 
LVL 11

Accepted Solution

by:
shaneholmes earned 1024 total points
ID: 10679175
mmmm, not unless your using the initialization and finalization sections

Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10679202
Never mind you can't use that either unless you have something in the interface section, whether it be a var or another unit declared in the uses clause.

Shane

You got my stumped!

Shane

0
 
LVL 17

Expert Comment

by:geobul
ID: 10679417
unit Strange;

interface

implementation

uses unit1;

begin
  // do something here;
end.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:shaneholmes
ID: 10679581
Yup, good thinking geobul, i forgot about that....

then you could also use the initialization & finalization section as well

Shane

unit Strange;

interface

implementation

uses unit1;

procedure DoSomething(MyObject: TMyObject);
begin
 //
end;

initialization
begin
 myObject:= TmyObject.Create;
 DoSomething(MyObject);
end;

finalization
  myObject.free
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10679719
robert, you remembers me to restart qow and qom :-))

coming soon
- picture fade effects (qow)
- swarm simulation logic (qom)

meikl ;-))
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10679942
qow available :-))
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 10684010
Hmm... wonder if someone will come up with Question of the Century and Question of the Millenium? ;-)
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10684392
Sorry, i should have told that uses needs to be allowed, but of course the uses in the implementation section is good enough.
So the question is effectively answered by geobul and shaneholmes. I think i split the points.

I came across this interesting Delphi trick when i wrote a plugin system for a component and ended up with a unit only
exporting a string const.
The bulk of the work was done by calling a register function in the initialization section. So Strange is still used in
another unit, but only import into Strange happens.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 10690973
If you Include a file with the {$I} directive, you can do this.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10693303
I do not consider including a file into the interface section an empty interface section.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10697317
My gut feel is that you don't have to worry about clean-up.  Interfaces are cleaned up automatically.  Therefore, your code is a little simpler and maybe quicker to develop.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10697860
interface <> interface section
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10705395
geobul, you will get points also
0
 
LVL 17

Expert Comment

by:geobul
ID: 10711088
Thanks Robert :-) The question was interesting and forced me to remember something well forgotten - that a unit could have begin..end. part.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10712245
I plan to write a text about the very fringes of Delphi.
Currently i have "empty interface section" and "private constructor". Anyone knowing other tricks?
0
 
LVL 17

Expert Comment

by:geobul
ID: 10712828
What about this OOP technique:

type
  TAncestorClass = class(TObject)
    procedure Bar; virtual;
    procedure Foo; virtual;
  end;

  TDescendantClass = class(TAncestorClass)
    procedure Bar; override;
    procedure Foo; reintroduce;
  end;

procedure TAncestorClass.Bar;
begin
  ShowMessage('Ancestor.Bar');
end;

procedure TAncestorClass.Foo;
begin
  ShowMessage('Ancestor.Foo');
end;

procedure TDescendantClass.Bar;
begin
  ShowMessage('Descendant.Bar');
end;

procedure TDescendantClass.Foo;
begin
  ShowMessage('Descendant.Foo');
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  aClass: TAncestorClass;
begin
  aClass := TDescendantClass.Create;
  try
    aClass.Bar; // calls TDescendantClass method - native behaviour
    aClass.Foo; // calls TAncestorClass method - not that native but very useful
  finally
    aClass.Free;
  end;
end;

Regards, Geo
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10723345
Robert,

How "fringy" do you want to get?  You can solicit ideas from a lot of sources.  I'm not sure that an EE Delphi Forum question is an appropriate location for such submission.  However, you might use EE to feed some other collection mechanism for your article as well as Delphi user groups and bulletin boards.

If you grouped your solicitations into categories, you might post many EE Delphi Forum questions and distribute the answers.  The problem you will face is that your questions will eventually 'age' off the first page.  So you might have to post weekly reference questions.

Maybe you can ask the Delphi Forum page editor to set aside some static space for your catetory questions.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10723354
>Maybe you can ask the Delphi Forum page editor

here i am, still listening :-))
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10724315
meikl,

Although this isn't my question, I might better explain this "fringy" idea of mine. :-)

Robert is interested in collecting ideas from Delphi developers that either aren't well known/understood or that are infrequently used (but situationally useful).  Rather than treating this research as a common question, create a special static place on the Delphi Forum page for his question(s).  They will have a limited lifetime and will be closed and removed within an agreed upon period.  I am thinking along the lines of the current page sections you have for "Hot Solutions".

In addition, Robert might organize a team of Delphi developers to glean "fringy" ideas from the PAQ pool.

It just seems to me that such a project wouldn't readily fit into the current Delphi Forum structure (question type) and that the aging of questions would reduce the visibility of the questions and, thus, reduce the number of submissions.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10724407
BTW...a few years ago, I organized a team of user group members to create Delphi quiz questions and pointed them to the Delphi PAQ pool.  We divided the range of questions to prevent overlap.

============================
I would also think that a project to consolidate and categorize discussion threads from the PAQ pool would be quite useful.  I'm sure there are many duplicate questions and the Google search engine could produce better results if we were to supply some classification meta data to the PAQ pool.
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 10726143
I actually suggested "sticky postings" to CS before (erm... 2 years ago?)... but no news from 'em.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10729575
Sounds good to me :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10729662
well,
good suggestions,
but i cannot not free handle designissues or
specific sections.

i will see, if a subtopic can be esatblished,
like "couriouses and trickys around delphi"

meikl ;-)
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10731442
We might become an open-source, collaborative gold mine for the Delphi developer community.  I have ideas, but don't want to overly influence this.  I'm too much of a Delphi novice.
0
 
LVL 11

Author Comment

by:robert_marquardt
ID: 10731472
I am a member of Project Jedi (namely the JediVCL).
I think we ARE already an open-source, collaborative gold mine for the Delphi developer community :-)

BTW there is a really bad trick in it where properties are added dynamically at runtime!
0
 
LVL 46

Expert Comment

by:aikimark
ID: 10731675
robert,

I had JEDI in mind when I wrote my comment.  I've used some of the JEDI API wrappers and submitted an item to the project.  Project JEDI is quite good and I'm glad it exists.  However, the Delphi Forum PAQ and the EE Delphi community have a great unrealized potential (IMHO).  

Soapbox time...
What are the biggest differences between Delphi and VB?
1. marketshare
2. quality of online help
3. background resources - KnowledgeBase and MSDN

If I have a VB problem, I can usually find a good answer at microsoft.com.  I can't say the same if I have a Delphi problem and turn to borland.com.  Developer communities like EE are very important to the Delphi developer community.  However, I think there is enough material at EE to create a DelphiKB or more.  Such a project doesn't have to be confined to EE, but can sure start here.
0
 

Expert Comment

by:tgrigsby
ID: 12116069
I would suggest that the initialization and finalization are the only really useful bits since nothing can access the implementation otherwise.  This could be used to force certain steps to happen within an application without necessarily putting these startup and shutdown calls within the individual units themselves.  This would have some advantages that come to mind right away:

1.  Used correctly, this puts the initialization and finalization in one location, guaranteeing execution order.

2.  This allows the units being called by this no-interface unit to be more compartmentalized way -- they could be initialized in an application specific way without prior knowledge of how the application uses them.  

An example:
====================================================
unit AppToolboxInitialization;

interface

// This unit is used to do application-specific initialization of the toolbox components.  It does not provide
// any definitions that are used by the rest of the application.  It's sole purpose is to perform operations
// to initialize the toolbox without requiring a call from the application itself, thereby relieving the programmer
// form remembering this step.

implementation

Uses
  TBEnvironment,
  TBDataAccess,
  TBAppClassFactory,
  TBCOM;

procedure InitToolbox;
var
  SysMetrics : TtbMetrics;
begin
  CollectParams;
  CollectMetrics( SysMetrics );
  ResetAppMetrics( SysMetrics );
  ConnectionPool;  // referencing this method causes the fConnectionPool soliton variable to be instantiated.
  InitCOMFacility( DBConnectionParams, DriveList );
  InitClassFactory( DBConnectionParams, SysMetrics );
end;

procedure FinalizeToolbox;
begin
  FinalizeClassFactory;
  FinalizeCOMFacility;
  FinalizeConnectionPool;
end;

initialization
  InitToolBox;
finalization
  FinalizeToolbox;
end;
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question