Method for printing out an arraylist [closed] - printing

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have made an Arraylist of assistants (String name, int salary)
i would like to create a method that will print out all of the assistants, no matter how many we add to the list.
i want to be able to call the method from my run file when time is due.
how would i gå about making that method ?
thanks in advance

Assuming ArrayList definition to be: ArrayList asstList
private void PrintAssistnatList() {
for(Assistant asst:asstList) {
System.out.println("Name: "+asst.name+" salary: "+salary);
}
}

Related

Is it a good practice to use StringUtils in groovy, in that case? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 months ago.
Improve this question
I've just integrated a new devteam, which is using grails. I'm new to grails/groovy too, so the question is possibly stupid, but I need some advice.
The legacy code I'm manipulating is using a lot of StringUtils from apache, and I can't find a good point why they're doing that. I've suggested to use groovy truth instead, and avoid importing an unnecesseary class, but they keep on not correcting existing code, and using it in new code.
So, my question is : are there any advantages I did'nt see, for that use case ?
Example of code :
if (StringUtils.isNotEmpty(params.invoiceEventId)) {
invoiceEvent = InvoiceEvent.findById(params.invoiceEventId)
}
Thanks for your wisdom
Look at the source code of both solutions:
StringUtils
public static boolean isNotEmpty(final CharSequence cs) {
return !isEmpty(cs);
}
public static boolean isEmpty(final CharSequence cs) {
return cs == null || cs.length() == 0;
}
and StringGroovyMethods:
public static boolean asBoolean(CharSequence string) {
return string.length() > 0;
}
The methods are almost identical. The only difference, is that null-check in Groovy is done outside.
Ergo, there's no need to use the long call to the 3rd party library in Groovy or Grails.

How to dynamically make multiple Labels, Edits and etc. in Delphi? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I want users to create their own list of controls such as TEdit, TCheckBox, TLabel, and other things. But how can I make another, when I have to predefine every control, but I don't know how many objects to define?
This is what you should do to create each object knowing its class type:
var
Obj:TControl;
begin
Obj := TEdit.Create(AOwner);
with Obj do begin
//Set properties here...
...
Parent := Self; //Assuming that you're writing code in your form class. if not, use object variable pointing to your form instead of `self`
end;
end;
To store unknown number of objects, you can either use a dynamic array, or link list, or you can even use the Controls property of the form.
This is the start of what you want to do (basics). You have plenty choices for implementing this part of your application. For example, you can have an array of TControl in your form class, and using Length and SetLength functions you can figure out how many objects your user has added to the form.

How to make manual docking seamless / invisible? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am trying to use docking as an alternative to embedding (related question) a TForm into a TWinControl (in this case a TTabSheet).
The user shouldn't notice that there are two different forms at all.
How do I avoid the close button and "drag bar" at the top of the docked form?
A simplified version of my code:
var
TabSheet: TTabSheet;
Form: TSubForm;
begin
TabSheet := TTabSheet.Create(Self);
TabSheet.DockSite := True;
TabSheet.PageControl := MainPageControl;
Form := TSubForm.Create(TabSheet);
Form.ManualDock(TabSheet);
Form.Show;
end;
PS: I don't want to use a TFrame which would of course be another alternative.
Update:
In this specific situation I am now considering to use TTabControl instead of TPageControl, so I can put all the controls into the master form.
I am using MVC/MVA anyway so the logic is separated from the UI.

How Delphi objects work in code [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have been looking at system.pas
Delphi can call up to 65,000 memory blocks from windows
When Delphi makes an object dose it call a memory block for its data
And if so does the class some how load a register with a memory address for that memory block and an address for the methods too that is placed in another register.
Does any one know anything about this?
J Lex Dean.
With GetMem you call from windows a memory block that windows allocates up to 65,000 per process inside the 4 gig space. Depending on the fag depends on if the block is moved when resized with the data relocated in the resize or fixed and other issues.
Read about Windows or go to windows.pas and search on memory and call on your Delphi help
Thier is a lot of funny things with system.pas like1/ _ObjectProcess as if to add confustion to delphi programmers. Why do they not just put code in TObject. 2/ And how does code measure deliration size of an object.
Have a look at this excellent explanation about what's going on when Delphi creates new Class instances: The Rise and Fall of TObject from Hallvard Vassbotn
Although the original article appeared in 1998, most of it is still true for newer Delphi versions.
Here is the original article from The Delphi Magazine:The Delphi Magazine, July 1998
Where does your "65000 memory blocks" statistic comes from?
When a class instance is Created, the following class method is called before executing the Create method of the class (from _ClassCreate global function, which ensures that the instance is created only once, for all Create nested calls):
class function TObject.NewInstance: TObject;
Which calls GetMem to get memory from the heap, and then the following method:
class function TObject.InitInstance(Instance: Pointer): TObject;
This InitInstance method will:
Call FillChar() to put all the previously allocated memory to 0;
Initialize the Interface Table of the object.
The methods (i.e. not the interfaces) are defined in the class type itself, not during class instance creation.
There is no "register" containing what you say.
You have access to the object memory address by its self variable, or by trans-typing its variable to a pointer:
var O: TObject;
begin
O := TObject.Create;
writeln('O memory address is ',pointer(O));
O.Free;
end;
And before Delphi 2010 and its enhanced RTTI, you don't have access to all methods and fields of an object. Only published properties and methods are accessible to your code. But you must use RTTI. See TypInfo.pas unit.

Why is the value or constructor 'handler' not defined? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I tried to use object expression to extend the IDelegateEvent, but in fsi there was an error FS0039: The value or constructor 'handler' is not defined.
My codes are as follows:
type IDelegateEvent<'Del when 'Del:> Delegate> with
member this.Subscribe hanlder =
do this.AddHandler(handler)
{ new IDisposable with
member x.Dispose() =
this.RemoveHandler(handler) }
And the reference is Matthew Podwysocki's Blog:http://weblogs.asp.net/podwysocki/archive/2009/08/21/f-first-class-events-creating-and-disposing-handlers.aspx
Because of a spelling error hanlder =

Resources